How to cout?

Hello again, I need help on how to print out all the thress variables from the 3 switch cases on another page, what should I do do I need to use another statement? All help will be appreciated!!!
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
111
112
113
114
115
116
 #include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
    int Main_Dish, Side_Dish, Beverage;
    const int MainPrice1 = 1, MainPrice2= 2, MainPrice3= 3, MainPrice4= 4, MainPrice5= 5;
    const int SidePrice1= 6, SidePrice2= 7, SidePrice3= 8 ,SidePrice4= 9 ,SidePrice5= 10;
    const int BevPrice1= 11, BevPrice2= 12, BevPrice3= 13, BevPrice4= 14, BevPrice5= 15;

    cout<<"Welcome to ________________\n";
    system("pause");
    system("cls");
    cout<<"Our Main Dishes\n";
    cout<<"Dish1..........Price\nDish2..........Price\nDish3..........Price\nDish4..........Price\nDish5..........Price\n";
    cout<<"Please choose one\n";
    cin>>Main_Dish;
    switch(Main_Dish)
    {   case 0:
        break;
        case 1:
        cout<<"Dish1.........."<<MainPrice1<<endl;
        system("pause");
        system("cls");
        break;
        case 2:
        cout<<"Dish2\n";
        system("pause");
        system("cls");
        break;
        case 3:
        cout<<"Dish3\n";
        system("pause");
        system("cls");
        break;
        case 4:
        cout<<"Dish4\n";
        system("pause");
        system("cls");
        break;
        case 5:
        cout<<"Dish5\n";
        system("pause");
        system("cls");
        break;
        }
    cout<<"Our Side Dishes:\n";
    cout<<"Sidedish1..........Price\nSidedish2..........Price\nSidedish3..........Price\nSidedish4..........Price\nSidedish5..........Price\n";
    cout<<"Please Select One Side Dish";
    cin>>Side_Dish;
    switch(Side_Dish)
    {   case 0:
        break;
        case 1:
        cout<<"Sidedish1\n";
        system ("pause");
        system("cls");
        break;
        case 2:
        cout<<"Sidedish2\n";
        system ("pause");
        system("cls");
        break;
        case 3:
        cout<<"Sidedish3\n";
        system ("pause");
        system("cls");
        break;
        case 4:
        cout<<"Sidedish4\n";
        system ("pause");
        system("cls");
        break;
        case 5:
        cout<<"Sidedish5\n";
        system ("pause");
        system("cls");
        break;
        }
    cout<<"Beverages\n";
    cout<<"Beverage1..........Price\nBeverage2..........Price\nSidedish3..........Price\nSidedish4..........Price\nSidedish5..........Price\n";
    cout<<"Please Select One Beverage";
    cin>>Beverage;
    switch(Beverage)
    {
        case 0:
        break;
        case 1:
        cout<<"Beverage1\n";
        system ("pause");
        system("cls");
        break;
        case 2:
        cout<<"Beverage2\n";
        system ("pause");
        system("cls");
        break;
        case 3:
        cout<<"Beverage3\n";
        system ("pause");
        system("cls");
        break;
        case 4:
        cout<<"Beverage4\n";
        system ("pause");
        system("cls");
        break;
        case 5:
        cout<<"Beverage5\n";
        system ("pause");
        system("cls");
        break;
        }
cout<<endl;
return 0;
}






PS: I'm reaaaaaaaaallllllllllllllyjavascript:tx('sup')yyyyyyyyy a beginner and my code is not done yet don't be mad at my humble beginning plss XD
Last edited on
Hi,

You don't need to nest those switch statements, this is creating all the combinations - which isn't needed. You can have the switch statements for main dish, side dish & beverage each appearing one after the other - not nested.

Here is some pseudo code to help organise your program - copy these comments into the cpp file in your project. then write/ paste the code that goes with each comment. SO now the comments serve as documentation.

1
2
3
4
5
6
// get input for the user name & address info
// show the menu
// Select the main Dish
// select the side dish
// select the beverage
// print confirmation message of menu selections & customer info 


Try to come up with meaningful variable names eg FirstName, MiddleInitial LastName not FN, MI , LN .

Good variable and function names aid understanding, and the code should read like a story of what is happening.

Try to use functions if you can.

Good Luck !! :+)
Thank youuuuuuuu so much that's what I've been trying to figure out and i dunno how XD and yes I will change my variable my code above is just for a trial thanks a lot and btw my prof told us the flow of our program, it's like this:
Name of the restaurant>Main menu page (choose one)>Side Dish page (choose one)>Beverage page (choose one)>Confirmation page(if you want to change something>User info page >
Check out page(where all the info stored)>Thank you page..
Will the switch statement will suffice for the entire program? or should I add another statement?
Hi,

You need at least 3 switch statements, one for each of Main Dish, Side Dish, Beverage, maybe more if you are going to have other menus as well:

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
//get user input for the MainDishSelection variable
// show the MainDishSelection Menu Function
//your code

switch (MainDishSelection) {
         case 1:
                  // your code
                  break;
         case 2:
                   // your code
                  break;
         case 3:
                  // your code
                  break;
         // other cases
         //don't forget a default case to catch bad input
         default:
                 std::cout << "Bad Menu Selection\n";
}

//get user input for the SideDishSelection variable
// show the SideDishSelection Menu Function
//your code

switch (SideDishSelection) {
         case 1:
                  // your code
                  break;
         case 2:
                   // your code
                  break;
         case 3:
                  // your code
                  break;
         // other cases
         //don't forget a default case to catch bad input
         default:
                 std::cout << "Bad Menu Selection\n";
}

//get user input for the BeverageSelection variable
// show the Beverage selection Menu function
//your code


switch (BeverageSelection) {
         case 1:
                  // your code
                  break;
         case 2:
                   // your code
                  break;
         case 3:
                  // your code
                  break;
         // other cases
         //don't forget a default case to catch bad input
         default:
                 std::cout << "Bad Menu Selection\n";
}
Topic archived. No new replies allowed.