Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started