hello, i'm trying to program a 4 slot restaurant table code with a bool loop. I do not know how to make it so that if someone selects seat 1, the loop repeats but eliminates option seat 1 because it is already taken, and so on until it all seats are selected. I also have a problem because no matter what input i put for "what seat number?" it always outputs "seat1". I am also having trouble in that once a seat is selected, a request for a name appears. i want on the right hand side of the selection to show
"[...1...|...2...]
[...3...|...4...]"
but as the names are added per chosen seat, it automatically reflects the change.
here is my basic code, without the loop, and only selection of 1 seat option, then asks all names, then reflects values.:
Your problems are your conditions. bool seatnum = "1" returns a 1 as a successful assignment has taken place.
What you want is: (seatnum == "1") which is an actual Boolean expression. '==' is compare, '=' is assign.
seatnum also has dual definitions, as a string and as a bool. You also define the bool value directly in the condition for the if statement, as well as initialize it. You could likely change it to an int and the user enters either 1, 2, 3, 4.
You already use the entire std namespace, you don't need the std::. This won't flag an error, just saying that it's pointless.
1 2
//no matter what selection, it always outputs seat1
}
Well, the seat1 deal is due to the improper definition of seatnum. The brace after ends the main function.
#include <iostream>
#include <string>
usingnamespace std;
int n;
string name;
string nametwo;
string namethree;
string namefour;
int main()
{
loop:
std::cout << "What seat number?\n";//shows seat arrangement
std::cout << "[..1..|..2..]\n";
std::cout << "[--3--|--4--]\n";
std::cin >> n;
//logic boolean if then seat readout (need to edit to add names per selection)
if(n==1){
std::cout << "seat1=\n"; //first seat selected, then asks for name.
std::cout << "Name?";
cin >> name;}
elseif(n==2){
std::cout << "seat2=\n";}
elseif(n==3){
std::cout << "seat3=\n";}
elseif (n==4){
std::cout << "seat4=\n";}
//loop if invalid number is entered
do{
if(n<1||n>4){
cout << "please enter valid seat number.\n";goto loop;
}
elsebreak;
}
while(n<1||n>4);
//work in progress, see first seat selected for example
std::cout << "Name?";
cin >> nametwo;
std::cout << "Name?";
cin >> namethree;
std::cout << "Name?";
cin >> namefour;
//end summary (needs edit) make table
///SN#/name
///SN#x/namex/
//SN#y/namey/
//SN#z/namez
// show diagram summary in correspondence
std::cout << "Table:" << endl << "seat number:" << n <<endl << "Name:" << name <<endl;
std::cout << "[.." << name <<"..|.." << nametwo <<"..]\n";
std::cout << "[.." << namethree << "..|.." << namefour <<"..]";
// projected final function: selection of seat, enter name, auto changes diagram, reverse/edit names
// break point here, console auto-closes. can someone help with that pls?
return 0;
}
My question is: how can i do a loop that when you enter the seat number and name, it loops back, but eliminates the already chosen seats? repeating until all seats are chosen, then final output.