Loop start and stop

Have to type code simulation for waiting at restaurant but can't stop the loop.Here's my assignment we are only using ofstream and iostream libs:
Program #5

Using what you have learned with if statements and loops, you will design a simulation based on a trip to The Outback (which I like to do frequently on Friday and/or Saturday evenings).

You will accept as input a wait time, in minutes, to be seated at An Outback Steakhouse.

You will do a loop to simulate each minute that passes during waiting to be seated.


If you receive a wait time of longer than an hour, output to the screen "Going to another place to eat", otherwise....

You will loop and...

Output to the screen "Getting drinks at the bar" if 5 minutes pass
Output to the screen "Getting appetizers at the bar" if 15 minutes pass
Output to the screen "Deciding to eat at the bar" if 30 minutes pass
Output to the screen "Order another round of drinks" if 45 minutes pass

That's it.

Sample Run #1:

Please enter a wait time at Outback Steakhouse: 75

Going to another place to eat...

Sample Run #2:

Please enter a wait time at Outback Steakhouse: 15

Getting drinks at the bar
Getting appetizers at the bar

Sample Run #3:
Please enter a wait time at Outback Steakhouse: 55

Getting drinks at the bar
Getting appetizers at the bar
Deciding to eat at the bar
Order another round of drinks

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
//
//  main.cpp
//  Homework 5
//
//  Created by Patrick Stark on 11/5/15.
//  Copyright © 2015 Patrick Stark. All rights reserved.
//

#include <iostream>

using namespace std;

int main ()


{

    {
    int intWaitTime;
    
  
    
    
    
    cout << "Enter time to wait for seating: ";
    
    
    cin >> intWaitTime;

    
    if (intWaitTime > 60)
   
        cout << "Going to another place to eat!" << endl;
        
    }
    

    
   
        int intArrival = 0;
        
        intArrival++;
    
        while (intArrival > 5)
            
       
            cout << "Getting drinks at the bar."<< endl;
    
    
        while (intArrival > 15)
            
        
            cout << "Getting appetizers at the bar." << endl;
            
    
    
        while (intArrival > 30)
    
            cout << "Deciding to eat at the bar." << endl;
    
        while (intArrival > 45)
    
      
            cout << "Order another round of drinks." << endl;
    
        
       
 
    
    
    return 0;
    
    
    
    
        
} 
Last edited on
I'm really curious as to why most posts have such copious amounts of white space or more particularly extra lines. When it's (code) cleaned up a bit, you can tell where some obvious errors are.

Where is your loop?

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
//
//  main.cpp
//  Homework 5
//
//  Created by Patrick Stark on 11/5/15.
//  Copyright © 2015 Patrick Stark. All rights reserved.
//

#include <iostream>

using namespace std;

int main () {
    int intWaitTime;
    
    cout << "Enter time to wait for seating: ";
    cin >> intWaitTime;

    if (intWaitTime > 60)   
        cout << "Going to another place to eat!" << endl;
    else {    
        int intArrival = 0;
        
        intArrival++;
    
        while (intArrival > 5)       
            cout << "Getting drinks at the bar."<< endl;
	    
        while (intArrival > 15)        
            cout << "Getting appetizers at the bar." << endl;
            
        while (intArrival > 30)    
            cout << "Deciding to eat at the bar." << endl;
    
        while (intArrival > 45)      
            cout << "Order another round of drinks." << endl;    
        }
	
    return 0;        
}


I did modify braces so at least values over 60 would work according to spec.
I'm taking C++ online with my college, so I can't personally ask instructor. Don't know how to write this. When I email professor I don't get answer. Here's what else I tried, I cout loop number, but it doesn't go to next command of getting appetizers. My book doesn't explain.
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
    //
    //  main.cpp
    //  while5
    //
    //  Created by Patrick Stark on 11/6/15.
    //  Copyright © 2015 Patrick Stark. All rights reserved.
    //

    #include <iostream>
    
    using namespace std;
    
    int main ()

    {

    int intWait;
    
    int intInitialArrival;
    
    cout << "Please enter a wait time in minutes: ";
    
    cin >> intWait;
    
    if (intWait <= 60)
    
    {
        
        for (intInitialArrival=0; intInitialArrival < 60; intInitialArrival++)
        {
        
            
            
            
            
            while (intInitialArrival>5 && intInitialArrival < 60)
            
            {
            
                cout << "Getting drinks at the bar.\n"<<intInitialArrival++;
            }
            
            while (intInitialArrival>15 && intInitialArrival < 60)
                
            {
                
                cout << "Getting appetizers at the bar.\n"<<intInitialArrival++;
            }
            
            while (intInitialArrival>15 && intInitialArrival < 60)
                
            {
                
                cout << "Decided to eat at the bar.\n"<<intInitialArrival++;
            }
           
            while (intInitialArrival>15 && intInitialArrival < 60)
                
            {
                
                cout << "Order another round of drinks.\n"<<intInitialArrival++;
            }
            
           
        }
        
    }
    
    else
    {
    
    
    cout << "Going to another place to eat.\n";
        
    }


    return 0;


    }
Hey, I know how hard and flustering this can be. All I can say is don't give up. Keep practicing and you'll be fine. Here's how the code should look.

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
//
//  main.cpp
//  Homework 5
//
//  Created by Patrick Stark on 11/5/15.
//  Copyright © 2015 Patrick Stark. All rights reserved.
//

#include <iostream>

using namespace std;

int main(){
    
    int intWaitTime;
    
    cout << "Enter time to wait for seating: ";
    cin >> intWaitTime;

    if (intWaitTime >= 60){   
        cout << "Going to another place to eat!" << endl;
    }else{    
    
        while (intWaitTime >= 5 && intWaitTime < 15){       
            cout << "Getting drinks at the bar." << endl;
            break;
        }
	    
        while (intWaitTime >= 15 && intWaitTime < 30){        
            cout << "Getting drinks at the bar." << endl;
            cout << "Getting appetizers at the bar." << endl;
            break;
        }
            
        while (intWaitTime >= 30 && intWaitTime < 45){
            cout << "Getting drinks at the bar." << endl;
            cout << "Getting appetizers at the bar." << endl;
            cout << "Deciding to eat at the bar." << endl;
            break;
        }
    
        while (intWaitTime >= 45 && intWaitTime < 60){      
            cout << "Getting drinks at the bar." << endl;
            cout << "Getting appetizers at the bar." << endl;
            cout << "Deciding to eat at the bar." << endl;
            cout << "Order another round of drinks." << endl;
            break;
        }
        }
	
    return 0;        
}
Last edited on
Hope this is of some use for you

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
#include <iostream>

using namespace std;

int main() {
	int intWaitTime;

	cout << "Enter time to wait for seating: ";
	cin >> intWaitTime;

	if (intWaitTime > 60)	// for more than 60 seconds
		cout << "Going to another place to eat!" << endl;
	else {
		if (intWaitTime > 5)	// for wait time more than 5 seconds
			cout << "Getting drinks at the bar." << endl;

		if (intWaitTime > 15)	// for wait time more than 15 seconds
			cout << "Getting appetizers at the bar." << endl;

		if (intWaitTime > 30)	// for wait time more than 30 seconds
			cout << "Deciding to eat at the bar." << endl;

		if (intWaitTime > 45)	// for wait time more than 45 seconds
			cout << "Order another round of drinks." << endl;
	}
	return 0;
}


Enter time to wait for seating: 55
Getting drinks at the bar.
Getting appetizers at the bar.
Deciding to eat at the bar.
Order another round of drinks.
Last edited on
This is where I run into problems. The program need an increment operator and minute 5-15 says one thing, 15-30 adds another comment etc.
minute
1 Getting drinks at the bar.
2 Getting drinks at the bar.
3Getting drinks at the bar.
4 Getting drinks at the bar.


15 Getting drinks at the bar.
Getting appetizers at the bar.
16 Getting drinks at the bar.
Getting appetizers at the bar. etc......
I finally figured it out after tinkering with it. Thank you all who gave me suggestions and even worked on it. Other C++ sites the users will ban you and offer no help.
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
//
//  main.cpp
//  homework 5
//
//  Created by Patrick Stark on 11/7/15.
//  Copyright © 2015 Patrick Stark. All rights reserved.
//

#include <iostream>

using namespace std;

int main()

{
    int intWait;
    
    int intMinutes = 0;
    
    string drinks = "Getting drinks at the bar.\n";
    
    string apps = "Getting appetizers at the bar.\n";
    
    string strEat = "Deciding to eat at the bar.\n";
    
    string strRound = "Order another round of drinks.\n";
    
    cout << "Please enter a wait time in minutes:";
    
    cin >> intWait;
    
    if (intWait < 60)
   
    {
        while (intMinutes < intWait)
            
        {
           
            if (intMinutes> 5)
            {
                cout << drinks;
            }
            if (intMinutes>15)
            
            {
                cout<<apps;
            }
            if (intMinutes>30)
            {
                cout << strEat;
            }
            if (intMinutes>45)
            {
                cout << strRound;
            }
            
            
            
            intMinutes++;
        }
            
    }
    
    else
        {
        cout << "Going to another place to eat." << endl;
        }
    return 0;
    
    
}
Topic archived. No new replies allowed.