147k views
5 votes
1. Create a function called numberGuess. Function numberGuess will first choose a random number in the range 1 to 1000. The number that is chosen is what the user is supposed to guess. Following this, your function should then display the following

The player then types a first guess. The function responds with one of the following:






Your function must not stop asking for guesses until the user has provided a correct solution. Your program should keep telling the player Too high or Too low to help them narrow down the answer. Count the number of guesses the player makes. At the end when the user finally guesses correctly, print Either you know the secret or you got lucky! if the number of guesses were 10 or less. If the player guesses the number in 10 tries, then print Ahah! You know the secret! If the player makes more than 10 guesses, then print You should be able to do better!
-


- I already have some code however not sure if its 100% correct
Please review feedback will appreciated, thanks
#include
using namespace std;

int main()
{
int num, guess, tries = 0;
srand(time(0)); //seed random number generator
num = rand() % 1000 + 1; // random number between 1 and 1000
cout << "I have a number between 1 and 1000"< > guess;
tries++;

if (guess > num)
cout << "Too high!\\\\";
}
while(guess < num);
cout << "Too low!\\\\";
if(10<=guess)
cout << "\\Correct!either you know the secret or you got lucky" << tries << " guesses!" < {

} if (guess==10){
cout<<" Ahah! You know the secret!"< }
else


{
cout<< "You should be able to do better! ";
cout<< " Would you like to play again? (Y/N)";



}



}

User Sameera K
by
3.5k points

1 Answer

5 votes

You can edit this code whatever you want! Good luck.

1. Create a function called numberGuess. Function numberGuess will first choose a-example-1
1. Create a function called numberGuess. Function numberGuess will first choose a-example-2
User Stradas
by
3.5k points