i wrote this code and it works but it only asks the user to pick a seat once and then it assigns the seat and the code ends.i want it to ask over again untill my seats are filled and i can implement the top code.
this is the code
int main(){
Reservation object;
if (!object.availableSmoking() && !object.availableNonSmoking()) {
cout << "the plane is full";
cout << "the next flight leaves in 3 hours";
}
else {
if (!object.availableSmoking()) {
cout << "there are no smoking seats available";
cout << "would you like to be seated in the non smoking section?";
}
if (!object.availableNonSmoking()) {
cout << "there are no non smoking seats available";
cout << "would you like to be seated in the smoking section";
}
}
int answer;
do {
cout << "please type 1 for smoking or please type 2 for non-smoking\n";
cin >> answer;
if (answer == 1 && object.availableSmoking()) {
cout << "you are in the smoking section and your seat number is" << object.reserveSmoking(answer) << endl;
}
if (answer == 2 && object.availableNonSmoking()) {
cout << "you are in the non-smoking section and your seat number is" << object.reserveNonSmoking(answer) << endl;
}
} while (answer != 1 && answer != 2);
}
Turn your main() into a different function. Create a new main() that calls your function. The only real trick here was passing the Reserveation object as a parameter.
int reserveASeat(Reservation &object){
if (!object.availableSmoking() && !object.availableNonSmoking()) {
cout << "the plane is full";
cout << "the next flight leaves in 3 hours";
}
else {
if (!object.availableSmoking()) {
cout << "there are no smoking seats available";
cout << "would you like to be seated in the non smoking section?";
}
if (!object.availableNonSmoking()) {
cout << "there are no non smoking seats available";
cout << "would you like to be seated in the smoking section";
}
}
int answer;
do {
cout << "please type 1 for smoking or please type 2 for non-smoking\n";
cin >> answer;
if (answer == 1 && object.availableSmoking()) {
cout << "you are in the smoking section and your seat number is" << object.reserveSmoking(answer) << endl;
}
if (answer == 2 && object.availableNonSmoking()) {
cout << "you are in the non-smoking section and your seat number is" << object.reserveNonSmoking(answer) << endl;
}
} while (answer != 1 && answer != 2);
}
int main()
{
Reservation object;
do {
reserveASeat(object);
} while (object.availableSmoking() || object.availableNonSmoking());
}