can someone help me. My prof needed array and output

#include <iostream>
using namespace std;


int main(int argc, char** argv)


{
int size, crust, flavor, extra, order=0, total=0;

cout<<"Good day! Welcome to Don Rogelio's Pizza. \n";
do{
cout<<"\nPizza size: (1)Small (2)Medium (3)Large :";
cin>>size;
cout<<"\nPizza Crust: (1)Thin Crust (2)Regular Crust :";
cin>>crust;
cout<<"\nPizza Flavor: (1)Hawaiian (2)Pepperoni (3)Ham & Cheese (4)All Meat (5)All Cheese (6)Vegetarian :";
cin>>flavor;
cout<<"\nAdditional/Extras: (1)Pepperoni (2)Pineapple (3)Ham (4)Veggies (5)Meat (6)Cheese (7)None :";
cin>>extra;



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.";




}return 0;
}
Last edited on
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.

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
#include <iostream>
using namespace std;

struct Pizza
{   int size;
    int crust;
    int flavor;
    int extra;
    int cost;
};
const int MAX_PIZZAS = 10;

//  Returns true if a pizza was sucessfully ordered 
//          false if no more pizzas are wanted   
bool order_pizza (Pizza & p)
{   int order = 1;

    do
    {   p.cost = 0;
        cout << "\nPizza size: (0) Quit (1)Small (2)Medium (3)Large :";
        cin >> p.size;
        cout << "\nPizza Crust: (1)Thin Crust (2)Regular Crust :";
        cin >> p.crust;
        cout << "\nPizza Flavor: (1)Hawaiian (2)Pepperoni (3)Ham & Cheese (4)All Meat (5)All Cheese (6)Vegetarian :";
        cin >> p.flavor;
        cout << "\nAdditional/Extras: (1)Pepperoni (2)Pineapple (3)Ham (4)Veggies (5)Meat (6)Cheese (7)None :";
        cin >> p.extra;
        
        switch (p.size)
        {   case 0: return false;   //  No more pizzas
            case 1: cout<<"Your order is small"; 
                p.cost += 30; break;
            case 2: cout<<"Your order is medium";
                p.cost += 50; break;
            case 3: cout<<"Your order is large";
                p.cost += 70; break;
            default: cout<<"Invalid input."; 
                continue; 
        }
        switch (p.crust)
        {   case 1: cout<<" thin crust"; 
                p.cost += 35; break;
            case 2: cout<<" regular crust ";
                p.cost += 30; break;
            default: cout<<"\nInvalid input."; 
                continue; 
        }
        switch(p.flavor)
        {   case 1: cout<<" hawaiian pizza"; 
                p.cost += 50; break;
            case 2: cout<<" pepperoni pizza"; 
                p.cost += 65; break;
            case 3: cout<<" ham & cheese pizza"; 
                p.cost += 50; break; 
            case 4: cout<<" all meat pizza"; 
                p.cost += 80; break;
            case 5: cout<<" all cheese pizza"; 
                p.cost += 50; break;
            case 6: cout<<" vegetarian pizza"; 
                p.cost += 60; break;
            default: cout<<"\nInvalid input."; 
                continue; 
        }
        switch(p.extra)
        {   case 1: cout << " with extra pepperoni.\n"; 
                p.cost += 10; break; 
            case 2: cout << " with extra pineapple.\n"; 
                p.cost += 15; break;
            case 3: cout << " with extra ham.\n"; 
                p.cost += 10; break;
            case 4: cout << " with extra veggies.\n"; 
                p.cost += 15; break;
            case 5: cout << " with extra meat.\n"; 
                p.cost += 20; break;
            case 6: cout << " with extra cheese.\n"; 
                p.cost += 15; break;
            case 7: cout << " with no extra.\n"; 
                break;
            default: cout << "\nInvalid input."; 
                continue; 
        }
        cout<<"Would you like to change your order? (1)YES (2)NO: ";
        cin >> order;
    } while (order==1);
    cout << "The cost of this pizza is: " << p.cost << endl;
    return true;    //  pizza complete    
}
    
int main () 
{   Pizza   pizzas[MAX_PIZZAS];
    int     num_pizzas = 0;   
    int     total = 0;
    
    cout << "Good day! Welcome to Don Rogelio's Pizza. \n";
    while (num_pizzas < MAX_PIZZAS && order_pizza (pizzas[num_pizzas]))
    {   total += pizzas[num_pizzas].cost;
        num_pizzas++;
    }
    
    cout << "You ordered " << num_pizzas << " pizzas" << endl;
    cout << "Your total is: " << total << endl;
    cout << "Your order is complete" << endl;
    return 0;
}
Last edited on
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 continue if 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!
Topic archived. No new replies allowed.