urgent

how can i make it print " sorry the smoking are is full. Try the nonsmoking "
when the smoking count finishes
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
 # include <iostream>
# include <iomanip>
# include <cstring>

using namespace std;

int main()
{
    int seats [10] = {0};
    char Y = 'y';
    char N = 'n';
    char y;
    char n;
    char answer1;
    int answer2;
    int smoking = 1;
    int nonSmoking = 2;

    int currSmokingSeat = 0;
    int currNonSmokingSeat = 5;

    do {
        cout << " Would you like to make a reservation? Enter Y for yes, N for no:"<< endl;
        cin >> answer1;
        if (answer1 == Y )
        {
            cout << "Please enter 1 for smoking, 2 for nonsmoking:"<< endl;
            cin >> answer2;

		    cout << "Boarding pass:"<< endl;
		    int assigned = -1;
            if(answer2 == 1 && currSmokingSeat < 5)
            {

            	seats[currSmokingSeat] = 1;
                assigned = currSmokingSeat++ ;
            }
            else if(answer2 == 2 && currNonSmokingSeat < 10 )
            {
            	seats[currNonSmokingSeat] = 1;
            	assigned = currNonSmokingSeat++;
            }
            else
            {
            	cout << " No available seats" << endl;
            }

            if(assigned != -1)
            {
		        cout << " Seat:"<< "   "<< assigned + 1 << "     " << " Area:"<< "    ";
		        if(assigned < 5 )
		        {
		        	cout << " smoking"<< endl;
		        }
		        else
		        {
		        	cout << " nonsmoking"<< endl;
		        }
            }
        }
    }
    while ( answer1 == Y);

    return 0;
}
So what are the conditions that apply when you want to put out that message?

- Smoking seat requested
- Smoking section is full

So it becomes simply:
1
2
3
4
5
  const int max_smoking_seats = 5;

  if (answer == 1 && currSmokingSeat == max_smoking_seats)
  {  cout << " sorry the smoking area is full. Try nonsmoking" << endl;
  }


Note that if you include this in your existing if/else logic, you will loop back to the "do you want to make a reservation" question. You probably want to make it a little friendlier and ask "Do you want a non-smoking seat" and then either exit if no, or continue and force answer2 = 2.
Last edited on
were should i put this code ?
Topic archived. No new replies allowed.