Airseat program

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 <conio.h>
#include <string>

using namespace std;
int main()
{
    char SeatNo = ' ',UserAns;
    string Available [7] = {"1 ABCD", "2 ABCD", "3 ABCD", "4 ABCD", "5 ABCD", "6 ABCD", "7 ABCD"};
    int SeatRow = 0,PrintX;
  
	cout <<"/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\";
	cout << " \n\tWelcome to The World's Best Airline.\n\tIn our plane we have 7 rows and each has 4 seats (A, B, C, D)."; 
	cout << " \n\tPlease select the seat to reserve for yourself.\n\n\t\t\t\t\t\tThank You.\n\n"; 
	cout <<"/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\";

    do
    {
		// select the seat which one user wants
                cout <<"\n********************************************************************************\n";
				cout << "\nPlease select the row No. From 1 to 7  : ";
                cin >> SeatRow;
                cout << "\nPlease select the Seat No. From A to D : ";
                cin >> SeatNo;
				SeatNo = static_cast<char>(toupper(SeatNo));
               
				PrintX = 2 + SeatNo - 'A';

                if(Available [SeatRow-1][PrintX] == 'X')
					{ //this will check seat is available or not, if it's not then it will ask again....

                      cout <<"\nSent No. '"<< SeatRow<<SeatNo<<"' seat is reserved, Please select other Seat:" << endl;
                      continue; 
					}
                 else
					 // if seat not available it will show massage to select other seat...
                      Available [SeatRow - 1][PrintX] = 'X';
                      cout << "\nWould you like to select another seat?\n\nIf Yes type \"y or Y\", If No type \"n or N\" :-";
                      cin >> UserAns;
                
    } 
		 
	while (UserAns == 'Y' || UserAns =='y'); // if user select yes, it will repeat again
		cout <<"\n********************************************************************************\n";
		
				cout <<"\n \t\t ************************";
				for(int i=0; i<7; ++i)// getting info..
					 {
		               cout <<"\n\t\t * \tRow " << Available [i] <<"\t*"<< endl;
					 }
				cout <<" \t\t ************************\n";

	cout <<"\n Your selected seats reserved for you." << endl;
    cout << "\n Thank you For Choosing World's Best Airline. \n" << endl;
   
    _getch();
    return 0;
}







this my program I have trouble with available seat my program suppose to show seat only between A to D but program allows the user to choose seats that are not available like 8E, 0C and 7F . need help please.... :)
Last edited on
use code tags and proper indentation, it makes the code easier to read so we can help faster.

EDIT: as for your question, what do you want to do when you receive bad input? loop again until good input/exit the program/skip the section?
Last edited on
Topic archived. No new replies allowed.