Hi guys, im doing an assignment to create a c++ program that enables a user to book a seat in an airline reservation, i have managed to write out a code but i keep getting two error messages and i have no idea how to fix it, here is my code
#include <iostream>
usingnamespace std;
#include <cctype>
using std::toupper;
int main()
{
constint seats = 10;
int flight [seats] = { 0 };
int passenger = 0;
int secondclass= 6;
int firstclass= 1;
int choice;
char response;
while ( passenger < 10 )
{
cout << "Welcome to SHARMA Airline reservation system\n";
cout << "Please, choose which class you would like a seat in:\n";
cout << "Press 1 for First class\n";
cout << "Press 2 for Second class\n";
if ( choice == 1) //if choice 1 (firstclass)
{
if ( !flight[ firstclass ] && firstclass <= 5 )
{
cout << "You have chosen First class\n";
cout << "Your seat number is:\n " << firstclass << endl;
flight [firstclass++] = 1;
passenger++;
}
elseif (firstclass > 5 && secondclass <= 10);
{
cout << "Sorry, but all the seats in the First class are now full\n";
cout << "Would you like a seat in the Second class?\n";
cout << "Please press Y or N\n";
cin >> response;
if ( toupper( response ) == 'Y' )
{
cout << "You have choosen Second class\n ";
cout << "Your seat number is:\n" << secondclass << endl;
flight[ secondclass++ ] = 1;
passenger++;
}
else
cout << "The next flight leaves in 3 hours\n";
}
{
if ( !flight [secondclass] && secondclass <=10)
{
cout << "Your seat is:\n" << secondclass << "in Second class" << endl;
flight[ secondclass++ ] = 1;
passenger++;
}
elseif ( firstclass <=5)
{
cout << "The Second class area is full\n";
cout << "Would you like a seat in the First class section?\n";
cin >> response;
if (toupper( response ) == 'Y')
{
cout << "You have chosen First class\n";
cout << "Your seat number is:\n " << firstclass << endl;
flight [firstclass++] = 1;
passenger++;
}
else
cout << "Next flight in 3 hours\n";
}
}
}
}
return 0;
}
here are the two warnings i get:
warning C4390: ';' : empty controlled statement found; is this the intent?(line 33)
warning C4700: uninitialized local variable 'choice' used (line 23)
feel free to make any improvements on my codeing aswell im just a begginer!
They are not errors, just warnings, but good warnings that show you the errors you've made.
First one points out that you put a semicolon after the if on line 33.
The second shows you that you don't assign a value to choice before using it on line 23.
Remove the semi colon on line 32.
Also you got int choice i am looking at the program i belive that this is to navigate through the menu, so you might want to add cin >> choice; somewhere.
cos the user will be input this it does not need to be initialiase.