Hello again, im writing a program where there are a number of cases which are constantly repeated in a do-while loop until the user decides to end the program, but I cant find a way to disallow the repeating of a particular choice, say, choice a' being chosen again instead of another choice, b,c,d, etc. there is a switch statement after the 'do' portion with the list of cases and their respective outputs, but im not sure how to disallow a case from being chosen more than once. Thanks for reading.
If you mean again (as in preventing twice in a row) then just store the last option used in a variable and compare with the next option.
If you mean after say option 1 is pressed then you cant do it again then you can just do something simple like have a boolean variable set to true once the option has been run and checking that bool would prevent it from running again.
switch (choice)
{
case'a':
cout << "Enter an even bet: ";
double evenBet;
cin >> evenBet;
if (evenBet >= 0.00 && evenBet < startingCash)
{
newTotal = startingCash - evenBet;
cout << name << ", you have $" << newTotal << " left" << endl;
}
if (evenBet > startingCash)
{
cout << endl; cout << "Cannot bet that much! Try again." << endl;
}
elseif (evenBet < 0)
{
cout << endl; cout << "Invalid bet! Try again." << endl;
}
break;
I cant get around how to set up a bool to allow it once and not allow it a second time. would I t be something like initializing constant bools for each choice, a-d, and making a long "if" statement that diallows any repetition, with something like an initialized constant bool named choice and saying
1 2
if (choiceA > 1)
cout<< "Try another choice you haven't used"<<endl;
I tried rewriting it that way, but I don't think it applies directly to how the program should flow in my case. Here is the total code I have so far. It is a homework assignment, so some general guidelines and hints are appreciated rather than me simply plagiarizing any code you give out to me. So far this runs well, but doesn't disallow for the input of a variable once it has already been entered. thanks