0% found this document useful (0 votes)
417 views

Guessing Game Flowchart

The document describes the logic for a guessing game program where a random number is generated between 1-50 and the user tries to guess it within 20 attempts. It includes initializing variables like the random number, user guess, and attempt counter. It has a main loop that gets the user's guess as input, checks if it is too high, too low, or correct, and increments the attempt counter accordingly. If the user guesses correctly or reaches the limit, it asks if they want to play again before exiting.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
417 views

Guessing Game Flowchart

The document describes the logic for a guessing game program where a random number is generated between 1-50 and the user tries to guess it within 20 attempts. It includes initializing variables like the random number, user guess, and attempt counter. It has a main loop that gets the user's guess as input, checks if it is too high, too low, or correct, and increments the attempt counter accordingly. If the user guesses correctly or reaches the limit, it asks if they want to play again before exiting.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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