Question

A program for estimating a randomly generated number in the range of 0-99 will be designed.When the user enters a number, the program will direct the "enter a larger / smaller number" to ensure that the produced count is found. warning will be given when the number produced by the computer is found. how many steps I have answered will be shown in the sample program output below. design the c ++ program that performs these operations
Translation of the sample given in the picture:
enter the number you guessed: 40
enter a larger number
Repetition of the top two samples
Repetition of the top two samples
Repetition of the top two samples
Repetition of the top two samples
Repetition of the top two samples
Repetition of the top two samples
Repetition of the top two samples
Translation of the sample given in the picture:
enter the number you guessed: 71
congrulations!!!
you found the number 71 produced by the computer in 8 steps

2. (25p.) Bilgisayarın 0-99 aralığında rastgele ürettiği bir sayıyı tahmin etme programı tasarlanacaktır. Program, kullanıcı

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include<iostream>
#include <stdlib.h>//for rand() and srand()
#include <ctime>//for time()
using namespace std;
int main()
{
    srand(time(0));
    int rn=rand()%100;//to generate random number
    int gn=101;//We will store our guessed number here
    //taking such a number which won't satisfy in first time
    int cnt=0;//To count number of moves
    cout<<"Lets Start the Guessing Game"<<endl;
    cout<<"You have to guess the number between 0 - 99"<<endl;
    while(rn!=gn)
    {
        cout<<"Enter the number you have guessed : ";
        cin>>gn;
        cnt++;
        if(rn>gn)
        {
           cout<<"Enter a greater number."<<endl;
        }
        else if(rn<gn)
        {
           cout<<"Enter a smaller number."<<endl;
        }
        else
        {
           cout<<endl<<"Congratulations...!!"<<endl;
           cout<<"You found the number "<<rn<<" produced by the computer in "<<cnt<<" steps"<<endl;
        }
    }
    return 0;
}

Screenshots: Lets Start the Guessing Game You have to guess the number between 0 - 99 Enter the number you have guessed : 50 Enter a gre

.. .. .. Lets Start the Guessing Game You have to guess the number between 0 - 99 Enter the number you have guessed : 50 Ente

You might think why I used srand(time(0)) the reason I because rand() function has an algorithm, meaning there are steps that can be repeated to obtain a certain result so its outcome will always be the same. You change this by using a "seed" a good "seed" in this case is time() since it is always changing. So time(0) will return the current time.

Hope you like my answer? .

Add a comment
Know the answer?
Add Answer to:
A program for estimating a randomly generated number in the range of 0-99 will be designed.When...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT