switch(size)
{
case 1: cout<<"Your order is small";
total=total+30; break;
case 2: cout<<"Your order is medium";
total=total+50; break;
case 3: cout<<"Your order is large";
total=total+70; break;
default: cout<<"Invalid input."; break;
}
switch(crust)
{
case 1: cout<<" thin crust";
total=total+35; break;
case 2: cout<<" regular crust ";
total=total+30; break;
default: cout<<"\nInvalid input."; break;
}
switch(flavor)
{
case 1: cout<<" hawaiian pizza"; total=total+50; break;
case 2: cout<<" pepperoni pizza"; total=total+65; break;
case 3: cout<<" ham & cheese pizza"; total=total+50; break;
case 4: cout<<" all meat pizza"; total=total+80; break;
case 5: cout<<" all cheese pizza"; total=total+50; break;
case 6: cout<<" vegetarian pizza"; total=total+60; break;
default: cout<<"\nInvalid input."; break;
}
switch(extra)
{
case 1: cout<<" with extra pepperoni.\n"; total=total+10; break;
case 2: cout<<" with extra pineapple.\n"; total=total+15; break;
case 3: cout<<" with extra ham.\n"; total=total+10; break;
case 4: cout<<" with extra veggies.\n"; total=total+15; break;
case 5: cout<<" with extra meat.\n"; total=total+20; break;
case 6: cout<<" with extra cheese.\n"; total=total+15; break;
case 7: cout<<" with no extra.\n"; break;
default: cout<<"\nInvalid input."; break;
}
cout<<"Would you like to change your order? (1)YES (2)NO: ";
cin>>order;
switch(order)
{
case 1: order=order +0; break;
case 2: order=order +1; break;
}
}
while(order==1);
{
cout<<"\n";
cout<<"\nThe total is " <<total;
cout<<" PHP.";
You didn't include your problem statement, so i have no idea what your prof means by "needing an array". Are you supposed to be able to order multiple pizzas?
The switch (code) is entirely unnecessary.
The braces around the last three couts are unnecessary. In fact, they caused me to think they were meant to be under control of the while. They're not.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Here is the code using an array for the size information. Also
- I changed the variables from int to unsigned because negative values are not allowed.
- I initialized order and total inside the loop since they must be reset if the user wants to change their order.
- I added continueif the size is invalid. This will restart the do loop.
Try making similar changes for the crust, flavor and extra values. Once you have it working, try writing a function that will use the arrays to generate the menus too. The idea is that if something in the menu changes, you just want to change one of the Price arrays and everything else will Just Work.
In a real world program the array data would actually be in a separate file that the program would read. That way you wouldn't even have to recompile the program, you'd just change the file and voila!