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

I need to write a code in C++ for gussing game, this is what I have so far, it s

ID: 3764772 • Letter: I

Question

I need to write a code in C++ for gussing game, this is what I have so far, it should look like this....I need help to get it fixed.

#include
#include
#include

using namespace std;

int main(){

string guesser;
string picker;
int number;
int guess;
int response;
int try;
int CompGuess;

char correct;
char High;
char low;
char high;
string rand;
string role;

cout<< "Do you want to be guesser od picker?"<< endl;
getline(cin,role);

while(role != guesser & role != picker){
}
if (role == guesser){
   number = rand() % 100+1;  
   cout<< "Guess the number:"<    cin>>guess;
}
   while(guess !=number){
        if (guess > number)
           cout<< "Your number is too high"<         if (guess < number)
           cout<< "Your number is too low"<         cout<< "New try"<< endl;
        cin>>try;
   }

   if (guess == right){
      cout<<"You got the right number, congratulations!"<    }

   if (role == picker){
      High 100
      Low 1
      CompGuess -1
      bool correct = false
   }
    
   while(correct == false){
        rand ()%(High-low +1) +1;
        cout<< "Is response correct ?"<         getline>> response;
         
        if(response.find ("low") != string::npos){
           low=CompGuess +1;
        if(response.find ("high") != string::npos)
           high=CompGuess -1;
        if(right)
          correct=true;
}        
                 
return 0;
}

Explanation / Answer

#include <iostream>

#include<random>

using namespace std;

int main(){

string guesser;

string picker;

int number;

int guess;

string response;

int tries=0;

int CompGuess;

char correct;

int low;

int high;

string role;

cout<< "Do you want to be guesser or picker?"<< endl;

cin>>role;

while(role != "guesser" || role != "picker"){

cout<<"Enter again: ";

cin>>role;

}

if (role == "guesser"){

number = rand()%100 + 1;

cout<< "Guess the number:";

cin>>guess;

  

while(guess !=number){

if (guess > number) {

cout<< "Your number is too high";

} else if (guess < number) {

cout<< "Your number is too low";

}

cout<< "New try"<< endl;

tries++;

cin>>guess;

}

  

if (guess == number){

cout<<"You got the right number, congratulations!";

}

}

else {

high= 100;

low= 1;

CompGuess= -1;

bool correct = false;

  

while(correct == false){

CompGuess = rand()%(high-low +1) +1;

cout<< "Number is: "<<CompGuess<<". Is response correct ?";

cin>> response;

  

if(response.find ("low") != string::npos){

low=CompGuess +1;

} else if(response.find ("high") != string::npos) {

high=CompGuess -1;

}

if(response == "right")

correct=true;

}

cout<<"Correct computer guess is: "<<CompGuess<<" ";

}

  

cout<<" ";

return 0;

}