I have an assignment in CSC 101 where I must write a program where the user must think of a number between 1 and 19 inclusively, and the computer must guess it within 5 tries. Right now the program prompts me twice to enter high or low.
I have sort of gotten a template built using if statements, but I believe switch will work better. I can't think of another way to give the program the conditional to check if I gave it high or low. I don't want it to default to an error statement if the user forgot to hit space or something. That's why I have the prompt again.
cout << "is this your guess? Answer yes or no:" << guess << endl;
cin >> yesno;
if (yesno != "yes" || "no") {
cout << "Please answer only yes or no" << endl;
cin >> yesno;
}
if (yesno == "no")
{
cout << "Too high or too low? Answer too high or too low" << endl;
cin >> highlow;
if (highlow == "too high")
guess = guess - 5;
if (highlow == "too low")
guess = guess + 5;
if (highlow != "too high" || "too low")
{
cout << "Please anwer only too high or too low" << endl;
cin >> highlow;
}
It seems to always enter the last if statement in the yes==no block and it prompts me twice to enter too high or too low. It doesn't do it in my top block. I expect it to only ask me again if I don't input "too high" or "too low" Thanks in advance guys, any help is really appreciated.