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.

  1. First, include cstdlib (C Standard Library) and ctime (C Time) at the beginning of your program.
  2. Before you list the variables, include a section called Seed Random and type the following:
    1. srand( time( NULL ) );
  3. Whenever you want to generate the random number you will have a variable that receives it:
    1. random1 = (rand() % 50) + 1;
    2. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!