Question: -Please write the solustion as C++ program . The following program randomly generates an integer greater than or equal to 0 and less than 100.

-Please write the solustion as C++ program .

The following program randomly generates an integer greater than or equal to 0 and less than 100. The program should prompt the user to guess the number. If the user guesses the number correctly , the program outputs the an appropriate message. Otherwise, the program checks whether the guessed number is less than the random number, he program outputs the message your number is lower than the number. Guess again. Otherwise the program will prompt your number is higher than the number. Guess againThe program prompt the user to enter an another number until the user enters the correct number.

Hint:

To generate a random number, you should include cstdlib heder file and use function rand()

To generate different random numbers each time the program is run you need to use srand() which acts as the seed for the algorithm. By specifying different seed values, each time the program is executed, the function rand will generate a different sequence of random numbers. To specify a different seed, you can use use the function time of the header ctime,

Srand(time(0));

Num = rand()%100

Int number; // random

Int guess ; // from user

Bool isGuessed;

While is not guessed

{

Enter an integer number

Cin >> guess;// from user

You are right

Number to small

Number too big

}

The example for flag controlled loop

Flag controlled loops - A bool variable is defined and initialized to serve as a flag. The while loop continues until the flag variable value flips (true becomes false or false becomes true). In the following example the user is asked to enter numbers at the keyboard which are added together. To stop the addition the user enters a negative number.

-Please write the solustion as C++ program . The following program randomly

// Flag controlled loop #1 nclude using namespace std; int mainO double sum0.0; double value; bool nonNegative - true; while nonNegative) // Init flag // Test if nonNegative is true cin value; if(value

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!