So this loop will run, as long as the answer entered by the user is "no". If he enters yes, it will go into the if statement and do your thing, then exit the loop. But Im not sure if that is what you actually want to do with your program, but that is how you have structured it. Please let me know.
#include "class.h"
usingnamespace std;
int main()
{
while (1 == 1)
{
int tHappy = 0;
do
{
cout << endl << endl << "How happy is Tom on a scale of 1 to 100?: ";
cin >> tHappy;
if (tHappy > 100 || tHappy < 0)
{
firstRet("Wrong, try again!");
}
} while (tHappy > 100 || tHappy < 0);
int tHunger = 0;
do
{
cout << endl << endl << "How hungry is Tom on a scale of 1 to 100?: ";
cin >> tHunger;
if (tHunger > 100 || tHunger < 0)
{
secondRet("Wrong, try again!");
}
} while (tHunger > 100 || tHunger < 0);
vTom obj(tHappy, tHunger);
string choiceUser = "";
cout << endl << endl << obj.retStat() << endl << endl;
do
{
cout << "Repeat?: ";
cin >> choiceUser;
if (choiceUser == "yes")
{
}
elseif (choiceUser == "no")
{
return 0;
}
} while (choiceUser != "yes" && choiceUser != "no");
}
return 0;
}
Though it looks a bit cluttered in my opinion, but I didn't know any other way to do it.
To put it shortly, I wanted the whole program to repeat if you enter "yes" or to close if you enter "no", but if you didn't enter either one, it would ask you again to enter something.
I dont quite understand this part. I mean, if the choiceUser is yes, it doesnt repeat the program, it just does nothing.
Ive re-written what you did in a more cleaner way, tell me if it works as you want it to work.
Ive made it so it repeats the entire program if the user enters yes.
It seemingly works that way. If you enter "yes", it doesn't do anything and the do loop is complete, after which it goes to the end where it repeats the entire program cause I've put while(1 == 1) {} around the entire program. You can try running the code.
In other words, if you enter "yes", it doesn't do anything and goes to the bracket at line 51, where it reaches the end of the while loop, but since it's while( 1 == 1), the while loop will repeat forever and take you back to the very beginning of the code. But if you enter "no", it will manually return 0, but if you don't enter either, it asks you again to enter something.