c please thx Write a guessing game where the user has to gue

c++ please thx.

Write a guessing game where the user has to guess a secret number. After every g program tells the user whether their number was too large or too small until the us the right number. At the end the number of tries needed should be printed. Write? function for your implementation.

Solution

#include <bits/stdc++.h>
using namespace std;

void GuessNumber()
{


   int random = 0;
int guessed = 0;
int counter = 0;

srand(time(NULL)); //Set rendom number
random = rand() % 100 + 1; //Generate random numbers between 1 -100

cout<<\"Guess my number! \";

while(1)
{
counter++;

cin>>guessed;

if (guessed == random)
{
cout<<\"You guessed correctly in %d tries! Congratulations!\ \"<<counter;

if(counter <5) //if he answers within 5 guess
{
cout<<\"You have done awesome \";
}
else if(counter>5) //if he took more than 5 guesses
{
cout<<\"You tooke to long \";
}
break;
}

if (guessed < random)
printf(\"Your guess is too low. Guess again. \");

if (guessed > random)
printf(\"Your guess is too high. Guess again. \");

}


}
int main(void)
{
   GuessNumber();


return 0;   
}

c++ please thx. Write a guessing game where the user has to guess a secret number. After every g program tells the user whether their number was too large or to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site