i have made the following but the user should get 10 chances to guess the right number. after the 10 guesses or if the the guesser gets it correct it should ask if the player wants to play again and react accordingly.

#include <iostream>
#include <cstdlib>
#include <ctime>
 
using namespace std;
int main()
{
	srand(time(0));
	int randomNumber = rand() % 1000 + 1; 
	int guess = 0;
cout << "\tThe Number Guessing Game\n\n";

do
	{
		cout << "Enter your guess (#1-1000): ";
		cin >> guess; 
 
		if (guess < randomNumber) 
			cout << "Your guess was too low\n\n"; 
 
		if (guess > randomNumber) 
			cout << "Your guess was too high\n\n";
 
	} while (guess != randomNumber); 
 
	cout << "\nCongratulations! You've guessed the number.\n\n";
	system("pause");
	
	return 0;
}

>after the 10 guesses or if the the guesser gets it correct it
>should ask if the player wants to play again and react accordingly.
So wrap the whole thing in another loop and prompt for whether the user wants to play again.

thanks i will try that, but how do i go about doing that. i am a novice at this stuff and working on my own. i have been reading my text but can't seem to find it. any help would be appreciated

To look it up it's frequently called a nested loop since one loop sits inside another. Any type loop can be used in either position. Can have more than one nested loop, more than one layer of nested loops, etc.

outer loop //control whether to guess a number 
   generate random number to guess
   inner loop
      whatever
   end inner loop
   determine whether to continue or not
end outer loop
This article has been dead for over six months. Start a new discussion instead.