Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please someone else anwswer this it has been answered twice by the same person a

ID: 3827720 • Letter: P

Question

please someone else anwswer this it has been answered twice by the same person and is incorrect IN C++ (microsoft visual studios 2013) Write a program (with explanation //comments) with a method that plays the guess a number game. The program should allow the user to pick a number between 1 and 1000 in his head. The method should guess the user's number in a minimal amount of attempts. The method should ask the user "is the number greater than or less than the number " and the program gives a particular number. The user in some way just inputs (higher or lower) or (greater than or less than). There also has to be a way for the user to say the number has just been guessed. Of course, the user cannot answer incorrectly or change the number midstream. Note - if written efficiently, the method should be able to guess any number in 10 or less attempts

Explanation / Answer

Hi, Please find my implementation.

Please let me know in case of any issue.

#include <iostream>
#include <cstdlib>

using namespace std;

//function declaration
void playGame(int p);

int main(){

   int price;

   srand(time(0));
   char c;

   do{

       int guess = rand()%1000 + 1; // 1-10000

       playGame(guess);

       cout<<"Do you want to play agin(y/n) ? ";
       cin>>c;
   }while(c=='y'||c=='Y');

   return 0;
}

// function defination
void playGame(int p){

   int trie = 10;
   int count = 0;
   int userGuess;
   while(count < 5){
       cout<<"Guess a number in "<<1<<" and "<<1000<<" range : ";
       cin>>userGuess;

       if(userGuess == p){
           cout<<"You won the game!!!!"<<endl;
           return;
       }else if(userGuess < p){
           cout<<"Your guess is lower than the number"<<endl;
       }else{
           cout<<"You guess is higher than the price"<<endl;
       }

       count++;
   }

   cout<<"You have tried your maximum limit."<<endl;
}