So, I have this assignment and basically, I need to run the program until all seats are sold out of both halls. However, the program stops after one hall sells out, and doesn't move to the next hall. This is my code. (Everything else works the way it should)
Line 16 needs to be || instead of &&.
It currently says "keep going while both are not 0", so if either one becomes zero, it quits.
You want to say "keep going while either is not 0".
#include <iostream>
usingnamespace std;
int main() {
int hallSeats = 300;
int mezzSeats = 100;
while( hallSeats!=0 || mezzSeats!=0 ) { // note: || (at least one is non-zero)
int choice;
if( hallSeats!=0 && mezzSeats!=0 ) { // note: && (both are non-zero)
// accept choice from user
cout << "Enter 1 for Hall and 2 for Mezzanine" << endl;
cin >> choice;
}
elseif( hallSeats!=0 ) choice = 1 ; // only hall seats are available
else choice = 2 ; // only mezzanine seats are available
// rest of program
}
// ...
}
Thank you. I see what's happening, but I'm trying to make it so the program exits when all the seats are sold out. Right now, it exits when one hall sells out.
Sorry I should've explained better I did that and what JL said. When I do just what dutch says it doesn't register as 0 seats it just keeps running, and doesn't display the no more seats message