C++ CODING!!! Exercise 2 (15 points) Write a program that sells popcorn and drin
ID: 3572455 • Letter: C
Question
C++ CODING!!!
Exercise 2 (15 points)
Write a program that sells popcorn and drinks using the enumeration type. You must use the following within your program:
enum sizes {SMALL, MEDIUM, LARGE, JUMBO};
sizes popcornSize, drinkSize;
You should create a menu that asks the user to choose what size of drink they want and to choose what size of popcorn they want. Then you should print out the total cost of the drink and popcorn.
Prices: Popcorn Soda
Small 1.25 1.50
Medium 2.25 2.50
Large 3.50 3.75
Jumbo 4.25 4.50
Grading scheme: using enumeration type correctly: 10 points; using switch statement to calculate the cost: 5 points
Explanation / Answer
#include <iostream>
using namespace std;
enum sizes { SMALL, MEDIUM, LARGE, JUMBO };
int main()
{
sizes s;
s=SMALL;
cout<<s;
int si,si1;
float cost;
cout<<"Menu"<<endl;
cout<<"Prices: Popcorn Soda"<<endl;
cout<<"Small 1.25 1.50"<<endl;
cout<<"Medium 2.25 2.50"<<endl;
cout<<"Large 3.50 3.75"<<endl;
cout<<"Jumbo 4.25 4.50"<<endl;
cout<<"Enter size of popcorn 1.Small 2. Medium 3. Large 4. Jumbo"<<endl;
cin>>si1;
cout<<"Enter size of soda 1.Small 2. Medium 3. Large 4. Jumbo"<<endl;
cin>>si;
switch(si1){
case 1: cost=cost+1.25;
break;
case 2: cost=cost+2.25;
break;
case 3: cost=cost+3.50;
break;
case 4: cost=cost+4.25;
break;
}
switch(si){
case 1: cost=cost+1.50;
break;
case 2: cost=cost+2.50;
break;
case 3: cost=cost+3.75;
break;
case 4: cost=cost+4.50;
break;
}
cout<<"The total cost of popcorn and soda: "<<cost<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.