Question: Write a program that allows the user to guess a number 5 times. After each guess, the program will tell if the users number was
Write a program that allows the user to guess a number 5 times. After each guess, the program will tell if the users number was too low or too high, or it will give a congratulations, you won statement. The program also gets the users name and includes it in the output statements. Your algorithm may be in the comments at the top, or dispersed throughout the program as line comments.
How to do random
In order for the program to pick a number, you will use srand(). The following gives you instructions on how to do this.
- First, include cstdlib (C Standard Library) and ctime (C Time) at the beginning of your program.
- Before you list the variables, include a section called Seed Random and type the following:
- srand( time( NULL ) );
- Whenever you want to generate the random number you will have a variable that receives it:
- random1 = (rand() % 50) + 1;
- every time you use this line, itll give you a new random number from 1 to 50
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
