Loop inside switch

I am making a simple amusement park simulation for a class assignment but am having trouble looping statements inside of a switch. I have tagged my coding below
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <iostream>
#include "CinReader.h"
#include <fstream>
using namespace std;

CinReader reader;
string username;

void printImage (string imageFile);
void greeting ();
void entrance ();
void bathroom ();
void hotDogStand ();
void rides ();
void arcade ();


int main()



{
    greeting ();
    entrance ();
    bathroom ();
    hotDogStand ();
/*     rides ();
    arcade ();
*/
    return 0;
}

void greeting ()
{
    cout << "                       ********************************\n";
    cout << "                       *** WELCOME, ENTER YOUR NAME ***\n";
    cout << "                       ********************************\n\n";
    username = reader.readString();

    cout << "Well " << username << ", Let's visit an amusement park today.\n\n";
    cout << "-You walk across the entrance bridge into the open entrance yard of the park.\n";
    cout << "-The map below shows you your choices of sections in the park to visit.\n\n";

}

void entrance ()
{
    int choice = 0;
    do
    {

    cout << " *BATHROOM*    *HOT DOG STAND*    *RIDES*   *ARCADE*\n";
    cout << "     |                |              |          |   \n";
    cout << "     |                |              |          |   \n";
    cout << "     |                |  **********  |          |   \n";
    cout << "     --------------------*ENTRANCE*--------------   \n";
    cout << "                         **********              \n\n";
    cout << " What Would You Like To Do?\n\n";
    cout << "[1] Go to the Bathroom\n";
    cout << "[2] Get some food at the Hot Dog Stand\n";
    cout << "[3] Go on some rides\n";
    cout << "[4] Play some games in the arcade\n";
    cout << "[0] LEAVE THE PARK\n\n";
    cout << "enter your choice\n\n";
        choice = reader.readInt (0,4);

    switch (choice)
    {
        case 1:
            bathroom ();
       break;

        case 2:
            hotDogStand ();
        break;

//        case 3:
//            rides ();
//        break;

//        case 4:
//            arcade ();
//        break;

        case 0:
            cout << "Now Leaving the Amusement Park. Please Come Again\n\n";
//            quit = true;
        break;
        }
    }while (choice != 0);
}


void bathroom ()
{
    int bathroomChoice = 0;
    do
    {
    static bool lightsOn = false;
    if (lightsOn == true)
        {
        cout << "\nFilthy Bathroom.\n\n";
        cout << " What Next?\n";
        cout << "   1. Use the urinal\n";
        cout << "   2. Use a stall\n";
        cout << "   3. Wash your hands\n";
        cout << "   4. Go back to the Entrance\n";
            bathroomChoice = reader.readInt (1,4);

        char answer = 'y';
        answer = reader.readChar();
        if (toupper(answer) == 'Y')
            lightsOn = false;

        }
            else
        {
        cout << "\nThe room is pitch black.\n\n";
        cout << "Turn on the lights (y/n)\n\n";

        char answer = 'y';
        answer = reader.readChar();
        if (toupper(answer) == 'Y')
            lightsOn = true;
        }

    switch (bathroomChoice)
        {
            case 1:
                cout << " You finish your business. Don't forget to wash your hands!!\n\n";
                break;

            case 2:
                cout << " You open the door to the bathroom stall\n";
                cout << " The smell is so horrid you think about turning around\n";
                cout << " But you get the job done and leave the wretched stall\n\n";
                break;

            case 3:
                cout << " You wash your hands in what you hope is water and dry them with the air dryer.\n";
                cout << " Your hands are still somewhat wet. Air dryers suck ass.\n";
                break;

            case 4:
                entrance();
                break;

        }

    }while (bathroom != 0);
}

void hotDogStand ()
{
    int foodChoice = 0;
    int hotdogPicked = 0;
    int sodaPicked = 0;
    int funnelcakePicked = 0;
    int corndogPicked = 0;
    int milkshakePicked = 0;

    printImage ("HotDogShack.txt");




    cout << "\nWhat can I prepare for you\n\n";
    cout << "       1. Hot Dog\n";
    cout << "       2. Soda\n";
    cout << "       3. Funnel Cake\n";
    cout << "       4. Corn Dog\n";
    cout << "       5. Milkshake\n";
    cout << "       6. Return to the Entrance\n\n";
    cout << "               Please Choose\n\n";
            foodChoice = reader.readInt();

    switch (foodChoice)
    do
    {
        {
        case 1:
            cout << "One Hot Dog Coming Up...\n\n";
            hotdogPicked ++;
            break;

        case 2:
            cout << "One soda coming up...\n\n";
            sodaPicked ++;
            break;

        case 3:
            cout << "One funnel cake coming up...\n\n";
            funnelcakePicked ++;
            break;

        case 4:
            cout << "One Corn Dog coming up...\n\n";
            corndogPicked ++;
            break;

        case 5:
            cout << "One Milkshake coming up...\n\n";
            milkshakePicked ++;
            break;

        case 6:
            cout << "You consumed\n";
            cout << "...... " << hotdogPicked << " hot dogs\n";
            cout << "...... " << sodaPicked << " sodas\n";
            cout << "...... " << funnelcakePicked << " funnel cakes\n";
            cout << "...... " << corndogPicked << " corn dogs\n";
            cout << "...... " << milkshakePicked << " milkshakes\n\n";
            cout << "You are now returning to the entrance\n\n";

            entrance ();

            break;
        }
    }while (foodChoice = (1,5));
}

void printImage (string imageFile)
{
        ifstream fin(imageFile.c_str());
        if (!fin.fail())
        {
            char nextChar = fin.get();
            while (nextChar != EOF)
            {
                cout << nextChar;
                nextChar = fin.get();
            }
            fin.close();
        }
}



The hot dog stand is where I am stuck. I want the user to be able to choose as many items as possible. Then take them back to the options of food until they choose to leave. In which I want them to return to the entrance function. The hot dog stand code is below.
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
void hotDogStand ()
{
    int foodChoice = 0;
    int hotdogPicked = 0;
    int sodaPicked = 0;
    int funnelcakePicked = 0;
    int corndogPicked = 0;
    int milkshakePicked = 0;

    printImage ("HotDogShack.txt");




    cout << "\nWhat can I prepare for you\n\n";
    cout << "       1. Hot Dog\n";
    cout << "       2. Soda\n";
    cout << "       3. Funnel Cake\n";
    cout << "       4. Corn Dog\n";
    cout << "       5. Milkshake\n";
    cout << "       6. Return to the Entrance\n\n";
    cout << "               Please Choose\n\n";
            foodChoice = reader.readInt();

    switch (foodChoice)
    do
    {
        {
        case 1:
            cout << "One Hot Dog Coming Up...\n\n";
            hotdogPicked ++;
            break;

        case 2:
            cout << "One soda coming up...\n\n";
            sodaPicked ++;
            break;

        case 3:
            cout << "One funnel cake coming up...\n\n";
            funnelcakePicked ++;
            break;

        case 4:
            cout << "One Corn Dog coming up...\n\n";
            corndogPicked ++;
            break;

        case 5:
            cout << "One Milkshake coming up...\n\n";
            milkshakePicked ++;
            break;

        case 6:
            cout << "You consumed\n";
            cout << "...... " << hotdogPicked << " hot dogs\n";
            cout << "...... " << sodaPicked << " sodas\n";
            cout << "...... " << funnelcakePicked << " funnel cakes\n";
            cout << "...... " << corndogPicked << " corn dogs\n";
            cout << "...... " << milkshakePicked << " milkshakes\n\n";
            cout << "You are now returning to the entrance\n\n";

            entrance ();

            break;
        }
    }while (foodChoice = (1,5));
}


My loop is completely screwed up I know this. Just looking for some help on how to fix this problem. Thanks.
put the do while loop around the switch statement and put foodChoice = reader.readInt() inside it before the the switch and it should work
The switch is disconnected from its { } block. It needs to be within the do. You also need to put the call to readInt inside the do at the top. The while should be more like this,
while(foodChoice <= 5 && foodChoice >= 1);

What happens when entrance returns? I think that you need to draw some flow charts so that you understand the flow of your program. It seems like entrance is more of a main menu so what you really want is for each of the other functions to return back to main. All functions will eventually return to their caller. You probably want a loop in main that prints main menu over and over and after each function returns you simply print the entrance menu again.
Topic archived. No new replies allowed.