help urgeeeenttttt :"(!

i really need help i was absent in this class (arrays) and i dont know what to do :( i have an assignment due on sunday :"(!! i asked the doctor if he explain to me what i missed but he refused... so pleeaaase if u guys can help me with this q!
*Airline Reservation
A very small airline owns a small aircraft with a capacity of 10 seats. Write a program that keeps track of flight reservations. Your program should display the following:
Would you like to make a reservation? Enter Y for yes or N for no. (Your program executes until the user answers no). Each time the user answers yes, the following menu should be displayed:
Please type 1 for smoking
Please type 2 for nonsmoking.
If the person types 1, then your program should assign a seat in the smoking section (seats 1-5). If the person types 2, then the program should assign a seat in the section 6-10. Your program should then print a boarding pass indicating the seat number and whether it is in the smoking or the nonsmoking section.
Use an array to represent the seating chart of the airplane. Initialize all the elements of the array to zero indicating that all seats are available. As each seat is assigned, set the corresponding element to 1 to indicate that the seat is no longer available.
Your program should never assign a seat that has already been assigned. When the smoking section is full your program should display the message “Sorry, the smoking area is full. Try the nonsmoking area”. Similarly, if the nonsmoking section is full, your program should display “Sorry, the nonsmoking area is full.Try the nonsmoking area”.
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
  # include <iostream>
# include <iomanip>
# include <cstring>

using namespace std;

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

    for ( int i = 0; i < 10; i++)
    {
        cout << "Would like to make 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;

            if ( answer2 == 1)
            {
                for (i = 0; i <= 5; i++)
                {
                    if (seats[i] == 0 )
                    {
                        [i] = 1;
                        cout << " boarding pass:"<< endl;
                        cout << " Seat:" << "   " << i+1 << endl;
                        cout << " Area" << "   " << " nonsmoking"<< endl;


                    }
                }
            }
            else if ( answer2 == 2)
            {
                for ( i = 6; i<= 10; i++)
                {
                    if (seats[i] == 0)
                    {
                        [i] = 1;
                        cout << " boarding pass:"<< endl;
                        cout << " Seat:" << "   " << i+1 << endl;
                        cout << " Area" << "   " << " smoking "<< endl
                    }
                }
            }
    }


    return 0;
}


thats what i did so far and i have an error and i dont know what to do :( plz helppp
Last edited on
When I think of writing programs, I like to take the problem description and tear it to pieces and then look at each piece and think how I can write code for that particular piece.

Would you like to make a reservation? Enter Y for yes or N for no. (Your program executes until the user answers no).

This piece makes me think about a do while statement.
You may read about do while statements here: (in fact all the statements I will be mentioning can be read about here) http://www.cplusplus.com/doc/tutorial/control/

Each time the user answers yes, the following menu should be displayed:
Please type 1 for smoking
Please type 2 for nonsmoking.

This part needs to be inside the do while statement, but it also needs to be inside an if statement.

So in summary so far:
1
2
3
4
5
6
7
8
9
//print would you like to make a reservation menu (hint: cout >> "...";)
//ask for a char variable input (hint: cin >> ...;)
do {
    if(/*check if the user entered Y in the char variable*/)
    { //<---- do not forget these {} as part of the if statement
        //print smoking/nonsmoking menu choices
        //ask for an integer variable input
    }
} while(/*check if the user entered Y int the char variable*/);


Let me know if you would like more of this piece-by-piece stuff, and I will do some more.
thats what i did so far

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

using namespace std;

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

    cout << " Would you like to make a reservation? Enter Y for yes, N for no:"<< endl;
    cin >> answer1;

    do {
        if (answer1 == Y )
        {
            cout << "Please enter 1 for smoking, 2 for nonsmoking:"<< endl;
            cin >> answer2;
        }
    }
    while ( answer1 == y && answer2 == 1);
    {
        for (int i=0; i<5; i++ )
            if ( seats[i] == 0)
        {
            seats[i] = 1;
            cout << "Boarding pass:"<< endl;
            cout << " Seat:"<< "   "<< i+1 << "     " << " Area:"<< "    "<< " smoking"<< endl;
        }

    }
    return 0;
}
move lines 31 to 37 inside the if {} between lines 26 and 27. Then get rid of the { on line 30 and the } on line 39.

like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    do {
        if (answer1 == Y )
        {
            cout << "Please enter 1 for smoking, 2 for nonsmoking:"<< endl;
            cin >> answer2;
	        for (int i=0; i<5; i++ )
	        {
	            if ( seats[i] == 0)
		        {
		            seats[i] = 1;
		            cout << "Boarding pass:"<< endl;
		            cout << " Seat:"<< "   "<< i+1 << "     " << " Area:"<< "    "<< " smoking"<< endl;
		        }
	        }
        }
    }
    while ( answer1 == y && answer2 == 1);


Now that that is done the next step would be only assigning one of the seats instead of all five. So just scratch that for loop code and do this instead:
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
# include <iostream>
# include <iomanip>
# include <cstring>

using namespace std;

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

    cout << " Would you like to make a reservation? Enter Y for yes, N for no:"<< endl;
    cin >> answer1;

    do {
        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 /*did the user select smoking?*/
               && currSmokingSeat < 5 /*and are there any smoking seats left?*/)
            {
            	if()
            	seats[currSmokingSeat/*next available smoking seat integer*/] = 1;
                assigned = /*next available smoking seat integer*/;
                //add one to /*next available smoking seat integer*/ hint: variable++;
            }
            else if(answer2 == 2 /*did the user select nonsmoking?*/
               && currNonSmokingSeat < 10 /*and are there any nonsmoking seats left?*/)
            {
            	seats[currNonSmokingSeat/*next available nonsmoking seat integer*/] = 1;
            	assigned = /*next available nonsmoking seat integer*/;
            	//add one to /*next available nonsmoking seat integer*/ hint: variable++;
            }
            else
            {
            	//print some kind of error message if necessary since the user
            	//did not picked something other than 1 or 2
            	cout << "A seat was unable to be assigned." << endl;
            }
            
            if(assigned != -1)
            {
		        cout << " Seat:"<< "   "<< assigned + 1 << "     " << " Area:"<< "    ";
		        if(assigned < 5 /*smoking section (seats 1-5)*/)
		        {
		        	cout << " smoking"<< endl;
		        }
		        else //if(assigned > 5 /*nonsmoking section 6-10*/)
		        {
		        	cout << " nonsmoking"<< endl;
		        }
            }
        }
    }
    while ( answer1 == y && answer2 == 1);
    
    return 0;
}
ok nice but there aren't any loops in ur code
Topic archived. No new replies allowed.