Hi all, I just have a quick question. Is it ok to have two return 0; statements in your code? I can't seem to find a straightforward answer online, I am using it in a looping guessing game and without two return 0; statements it does not run properly. Please help in anyway you can, if I cannot have two then how would I fix it?
int main()
{
int num, guess;
string firstName;
bool isGuessed = false;
char playAgain = 'y';
srand(time(0));
cout << "Welcome to the Guessing Game. What is your name?" << endl;
cin >> firstName;
cout << "Hi " << firstName << endl;
while (playAgain== 'y' || playAgain == 'Y')
{
while (!isGuessed)
{
num = rand() % 2 + 1;
cout << "I am thinking of a number between 1 and 100,"
<< " can you guess what it is?" << endl;
cin >> guess;
cout << endl;
if (guess < num)
{
cout << "I'm sorry, that guess is too small." << endl;
}
if (guess > num)
{
cout << "I'm sorry, that is too big." << endl;
}
if (guess == num)
{
cout << "That is correct!"
<< " Congratulations on winning! Thank you for playing my game." << endl;
isGuessed = true;
}
cout << "Would you like to play again? (y/n)" << endl;
cin >> playAgain;
if (playAgain == 'y' || playAgain == 'Y')
{
isGuessed = false;
}
else
{
playAgain = 'n';
cout << "Thank you for playing!" << endl;
return false;
}
}
}
return 0;
}
This is what I have for my code, it runs fine but I am just not sure about my return statements. I originally had two "return 0;" statements but changed the first one to "return 1;" and it is "return false;", does it make a difference?Any suggestions?