Hi all,
Name's Liz, and this is my first post. I've been searching the forums and can't find a thread that answers my question, and I'm kind of stumped.
This is my second program for my CS class, so please bear with me and my lack of experience. I need to design a program that has the following requirements:
"In this assignment you are to write an application for a pizza parlor. The application will allow the user to order 1 or 2 pizzas with 1 or 2 ingredients. The pizzas come in [S]mall, [M]edium, and [L]arge sizes and the list of ingredients include [S]ausage, [P]epperoni, [M]ushroom, [O]nion, [G]reen pepper, [B]lack olive, and [C]anadian bacon.
The costs for the basic pies are $8.95, $9.95 and $10.95 respectively, with each ingredient adding an extra $1.15. Display the order back to them, along with the cost. "
So, if a user ordered two pizzas, one small with pepperoni, and one large with mushroom/black olive, to display the order, it should appear like this:
"Ordered: 1 S (P)
1 L (M, B)
Total cost: $23.35"
I'm having no trouble with the total cost, but I am stumped on how to display the order back to the user because I'm using while loops. Here's my code, and it's messy as heck:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
using namespace std;
int main()
{
int numPizzas, numIngred;
double costSize, total1, total2;
char pizzaSize, ingredType, orderedIng, orderedSize;
const double smallPizza = 8.95, medPizza = 9.95, largePizza = 10.95, ingredCost = 1.15;
//Loop for pizzas
cout << "Enter number of pizzas [1-2]: ";
cin >> numPizzas;
int count = 1;
int pizzaCount = numPizzas;
while ((pizzaCount >= 1)&&(pizzaCount <= 2))
{
cout << endl << "Pizza #" << count << ": " << endl
<< "[S]mall, [M]edium, [L]arge: ";
cin >> pizzaSize;
count++;
pizzaCount--;
switch (pizzaSize)
{
case 'S':
case 's':
costSize = smallPizza;
orderedSize = pizzaSize;
break;
case 'M':
case 'm':
costSize = medPizza;
orderedSize = pizzaSize;
break;
case 'L':
case 'l':
costSize = largePizza;
orderedSize = pizzaSize;
break;
default:
cout << "Please enter a valid pizza size." << endl << endl;
return 0;
}
total1 = (numPizzas*costSize);
cout << " # of ingredients [1-2]: ";
cin >> numIngred;
int count2 = 1;
int ingredCount = numIngred;
//Nested loop for ingredients
//I'm trying to figure out what action I should take after each case. Tried setting up another variable,
//orderedIng, so I could display the order...Stumped.
while ((ingredCount >= 1)&&(ingredCount <= 2))
{
cout << " #" << count2 << "[S, P, M, O, G, B, C]: ";
cin >> ingredType;
count2 ++;
ingredCount--;
switch (ingredType)
{
case 'S':
case 's':
orderedIng = 'S';
break;
case 'P':
case 'p':
orderedIng = 'P';
break;
case 'M':
case 'm':
orderedIng = 'M';
break;
case 'O':
case 'o':
orderedIng = 'O';
break;
case 'G':
case 'g':
orderedIng = 'G';
break;
case 'B':
case 'b':
orderedIng = 'B';
break;
case 'C':
case 'c':
orderedIng = 'C';
break;
default:
cout << "Please enter a valid ingredient." << endl << endl;
return 0;
}
total2 = (total1 + (numIngred*ingredCost*numPizzas));
}
}
//Here is where I need to display the order and the cost back to the user.
//cout.setf(ios::fixed);
//cout.setf(ios::showpoint);
//cout.precision(2);
//cout << endl << endl << "Ordered: 1 " << pizzaSize << " (" << ingredType << orderedIng << ")" << endl;
// << "Total cost: $" << total2 << endl << endl;
return 0;
}
|