Hello Anonomys,
Looking over your latest code gives me a better idea of what you need.
What I do not know is what you Ihave learned and what you can use.
I do not know if this will work for you, but I created a struct to contain a variable to keep track of the seats left and a 2D array of the seats.
Then in "main" I defined an array of the structs, so that each element corresponds to each of the flights. This way you can book a seat on any flight and the seat chosen will not affect any of the other flights.
I do not know if you can use functions yet, but I created a function that can print out the seats for any given flight.
At the moment it looks like this:
Welcome to COS1511 Flight Booking System
Enter full name: Etienne Navarre
The available travel times for flights are:
Depart Arrive
1. 07.00 09.30
2. 09.00 11.30
3. 11.00 13.30
4. 13.00 15.30
5. 15.00 17.30
6. Exit
Enter choice: 2
The available seats for departure time of 09.00 are as follows:
First Class (1920.00):
|A1|A2|A3| - - - - |A4|A5|A6|
|B1|B2|B3| - - - - |B4|B5|B6|
|C1|C2|C3| - - - - |C4|C5|C6|
|D1|D2|D3| - - - - |D4|D5|D6|
Economy class (1600.00):
|E1|E2|E3| - - - - |E4|E5|E6|
|F1|F2|F3| - - - - |F4|F5|F6|
|G1|G2|G3| - - - - |G4|G5|G6|
|H1|H2|H3| - - - - |H4|H5|H6|
|I1|I2|##| - - - - |##|##|##|
There are 50 left on the plane.
Please Enter A Seat: e3
The available seats for departure time of 09.00 are as follows:
First Class (1920.00):
|A1|A2|A3| - - - - |A4|A5|A6|
|B1|B2|B3| - - - - |B4|B5|B6|
|C1|C2|C3| - - - - |C4|C5|C6|
|D1|D2|D3| - - - - |D4|D5|D6|
Economy class (1600.00):
|E1|E2|**| - - - - |E4|E5|E6|
|F1|F2|F3| - - - - |F4|F5|F6|
|G1|G2|G3| - - - - |G4|G5|G6|
|H1|H2|H3| - - - - |H4|H5|H6|
|I1|I2|##| - - - - |##|##|##|
There are 49 left on the plane.
Press Enter to continue:
|
Not sure what you want to do with line "I", so I used the "##" to mark an unavailable seat. You could use something else or spaces, but it makes the output easier to work with. Plus you can use the contents of those elements when checking if someone entered the wrong seat.
Sorry about leaving the header file "<utility>". I had a thought at one time of using "std::pair", but decided against it as it was not needed. You can remove the header file "<utility>".
I added some variables in "main" and changed the if statements to:
1 2 3 4 5 6
|
if (menuChoice == 1)
{
departTime = times[menuChoice];
idx = 0;
}
|
Following the last if statement:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
if (menuChoice == 6)
{
return 0;
}
if (menuChoice < 6) // <--- This is temporary for now, but could be removed based on the last if statement.
{
DisplaySeats(flights, departTime, idx);
cout << " Please Enter A Seat: ";
cin >> seat;
seat[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(seat[0])));
|
Line 13 changes a lower case letter to upper case if needed. It saves on check each case later.
Let me know what you can use and I will see what I can come up with.
For now work in small steps and do not try to do everything at once or you may never get done in time. Compile often and test what you have done.
Here is a little trick to make things easier:
1 2 3 4 5 6 7 8 9 10 11 12
|
//string name; // <--- May not cause an error, but still needs the header file "<string>".
std::string name{ "Etienne Navarre" };
//cout <<
// "Welcome to COS1511 Flight Booking System\n\n"
// "Enter full name: ";
//std::getline(std::cin, name); // <--- Changed.
cout <<
"Welcome to COS1511 Flight Booking System\n\n"
"Enter full name: " << name << '\n';
|
Once you know that the code for entering a name works this allows you to skip that part and move on to the menu and the rest of the program.
When finished you can delete the added code or just reverse the comments in case you need it later.
Andy
P.S. meant to mention that the if statements would work better as a switch if you can use that.