Write a program that plays the HiLo guessing game with numbe

Write a program that plays the Hi-Lo guessing game with numbers. The program should assign the number 55, then repeatedly prompt the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or chooses to quit. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop. ** comment your prompt where necessary **The documentation should include what the program is doing, who wrote the program etc.

//write this whole program in c++ with using basic variables, loop and conditions.

Solution

#include <iostream>

#include <iomanip>

#include <ctime>

using namespace std;

char chr;

int main()

{

srand(time(NULL));                                          

int number=rand()%55+1;                                    

int guess;                                                  

int tries=0;                                                

   char answer;                                                

answer=\'y\';                 

while(answer==\'y\'||answer==\'Y\')

{

    while (tries<=20 && answer==\'y\'|| answer==\'Y\')

    {

    cout<<\"Enter a number between 1 and 55 \"<<endl;         

    cin>>guess;                                              

    tries++;                                                

    if(guess==0||guess>55)                                 

enters a number out of the peramiters

    {

     cout<<\"This is not an option try again\"<<endl;         

    }

   if(tries<20)                                           

    cout<<\"Tries left: \"<<(20-tries)<<endl;                  

    if(number<guess);                                        

    cout<<\"Too high try again\"<<endl;                        

    if(number>guess)                                         

    cout<<\"Too low try again\"<<endl;                         

    if(number==guess)                                         

    {

     cout<<\"Congratualtions!! \"<<endl;                         

     cout<<\"You got the right number in \"<<tries<<\" tries\"<<endl;

     answer = \'n\';

    }

    if(tries >= 20)                                              

    {

    cout << \"You\'ve run out of tries!\"<<endl;                     

    answer=\'n\';

    }

    if(answer==\'n\')

    {

     cout<<\"Would you like to play again? Enter Y/N\"<<endl;      

     cin>>answer;                                                 

     if (answer==\'N\'|| answer==\'n\')                               

     cout<<\"Thanks for playing!\"<<endl;                           

    else

        number=rand()%55+1;                                       

    }

    }

    }

cin>>chr;

    return 0;

}

Write a program that plays the Hi-Lo guessing game with numbers. The program should assign the number 55, then repeatedly prompt the user to guess the number. O
Write a program that plays the Hi-Lo guessing game with numbers. The program should assign the number 55, then repeatedly prompt the user to guess the number. O

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site