but if potatoes is not entered, then I would like to cout<<" ketchup"; forever until it is finally entered correctly.
I would like to output "ketchup" as long as the input is not equal to my desired cin>> which is potatoes. And then when cin>> is potatoes I would like to move on to a new cout statement such as cout<<"Mustard:";
I have tried if and else conditions. I have tried the while loop and it kept repeating without stopping.
Please just give me hints, as I want to figure this out with minimal help.
int main()
{
do
{
cout << ketchup;
cin >> UN;
} while(UN != "potatoes");
}
And the reason u get Ketchup repeated forever in
1 2 3 4 5 6
int main()
{
cout<< "Ketchup:";
cin>> UN;
while (UN!="potatoes");{cout<<"Ketchup:";}
}
is because you say "while UN does not equal potatoes, print ketchup."
So, if you don't give the user a chance for input to change UN's status or break
from it, then you get the infinite loop.
The devil is in the details! My {} were in the wrong places and that is indeed why I received the infinite loop. I was including while within the {}. The infinite loop was occurring in combo with an if condition also.