quick question

closed account (93v5LyTq)
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?
You can have as many return statements in a function as you like.

But if you show us the code, we can see exactly what you mean.

closed account (93v5LyTq)
#include <iostream>
#include <ctime>
#include <string>

using namespace std;

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?
closed account (93v5LyTq)
The 2 in the rand() % statement is supposed to be 100 but I set it as 2 just for testing purposes temporarily.
closed account (93v5LyTq)
Will it make a difference if i change return false; to break;?
Topic archived. No new replies allowed.