loop problem

I have a project for programming course, I wanted to make a program where I use loop (while, do while, for loop) to book seats for movies in the cinema. the problem that the loop is repeating the cout for 30 times, i just want the loop to stop if the person enter 31 or higher

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
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
//n refer to number of the seat, a refers to age
int n,a;
char name;
cout<<"\tWelcome to the cinema\n";
cout<<"\tPlease enter your name\n";
cin>>name;
cout<<"\tPlease enter your age\n";
cin>>a;
cout<<"\tPlease enter the seat you would like to reserve\n";
cin>>n;

while(n<=30)
{
    n+=1;
    if(a>=18)
    cout<<"\tyour seat is available and have been reserved\n";
    else if(a<=17)
    cout<<"\tyour seat is available, please show up with someone +18 to enter\n";
    
}
cout<<"\tthank you for using our service";

    return 0;
}
Hello,

Have a look at this example.
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
#include<iostream>
#include<conio.h>
#include<string>

using namespace std;
int main()
{
    int numberOfVisitors = 0;
    do
    {
        //n refer to number of the seat, a refers to age
        string name;
        int n,a;

        cout<<"\tWelcome to the cinema\n";
        cout<<"\tPlease enter your name\n";
        cin>>name;
        cin.clear();
        cout<<"\tPlease enter your age\n";
        cin>>a;
        cin.clear();
        cout<<"\tPlease enter the seat you would like to reserve\n";
        cin>>n;
        cin.clear();

        if(n<=30)
        {
            n+=1;
            if(a>=18)
            {
                cout<<"\tyour seat is available and have been reserved\n";
                numberOfVisitors++;
            }
            else if(a<=17) cout<<"\tyour seat is available, please show up with someone +18 to enter\n";
        }
        else cout << "Sorry, we only have 30 seats.\n";
        cout<<"\tthank you for using our service";
    }
    while (numberOfVisitors <=30);
    cout << "\n\n\nSorry, we are all sold out.\n";
    return 0;
}


Note that the condition of the loop should be something that you can count (in this case the number of reservations that has been made), since this tells the computer how many times the loop should be executed.

Kind regards, Nico
Last edited on
thank you for your help! I put the code and run it but in the end of the program it doesnt stop
it make me enter the name again from the start and so on.
i want to make the program stop after the
cout<<"\tthank you for using our service";
Topic archived. No new replies allowed.