Guessing Game Flowchart

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

int main(void)

srand(time(NULL))

To not have the same numbers


over and over again.

Main loop.
Initialize and allocate.

true
True

System number is stored in


here.

int number = rand() % 49 + 2

User guess is stored in


here.

Number of tries is stored


here.

int guess

int tries = 0

char answer

User answer to question is


stored here.
std::cout << number << "
"; // Was used for debug...

Get user number loop.


Get number.

true
True

:cout << "Enter a number between 1 and 50 (" << 20 - tries << " tries left): "

:cin >> guess

:cin.ignore()

Check is tries are taken up.

False

tries >= 5

Check number.

False

guess > number


False

True

guess < number

True

If not number, increment


tries.

False

:cout << "Too high! Try again.\n"

:cout << "Too low! Try again.\n"

tries >= 20

Or, user won.

False

tries++

False

Check for tries.

True

:cout<<"Congratulations!! " << std::endl

:cout << "You ran out of tries!\n\n"

:cout<<"You got the right number in " << tries << " tries!\n"

true

Loop to ask user is he/she


would like to play again.
Get user response.

True

:cout << "Would you like to play again (Y/N)? "

:cin >> answer


False

Check if proper response.

Check user's input and run


again or exit;

:cin.ignore()

answer == 'n' || answer == 'N' || answer == 'y' || answer == 'Y'


True

False

answer == 'n' || answer == 'N'


False

:cout << "\n\n\n"

:cout << "Please enter \'Y\' or \'N\'...\n"


True

:cout << "Thank you for playing!"

Safely exit.

:cout << "\n\nEnter anything to exit. . . "

:cin.ignore()

You might also like