i have the program written but i am having troble with a few parts. i am supposed to have the number of tries on the screen (which i do) but i need the program to ask the player if they want to play again after the game is done and act accordingly. it also should display the number of games played, number of correct guesses and average number of guesses it took to get the right answer. i do not know where the codes should go or how to write them in. any help would greatly be appreciated. i have been trying to learn this stuff from the book examples. i hope i coded this the right way

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main ()
{
	int num;
	int guess;
	bool done;
	int noOfGuesses = 0;
	int ncount;
	num = (rand() + time(0)) % 1000;
	done = false;
	while ((noOfGuesses < 10) && (!done))
	
	{
		cout << "Enter an integer greater"
			<< " than or equal to 0 and "
			<< "less than 1000: ";
		cin >> guess;
		cout << endl;
		noOfGuesses++;
		if (guess == num)
		{
			cout << "you guessed the correct "
				<< "number." << endl;
			done = true;
		}
		else
			if (guess < num)
				cout << "Your guess is lower "
				<< "than the number. \n"
				<< "Guess again!" << endl;
			else
				cout << "Your guess is higher "
				<< "than the number.\n"
				<< "guess again!" << endl;
			cout <<"Total gueses equal " << noOfGuesses << endl;

		
	}
	return 0;
	}

>but i need the program to ask the player if they want to play again after the game is done and act accordingly

Try creating a simple program; one that concentrates purely on getting the program to loop back to the beginning when the user chooses the option to play again.

put the whole thing you want to repeat in a do- while loop...
ask each time before the loop ends if the user wants to play again...
and keep a count of no. of times the loop runs...that would be no. of games played...
sum up noOf guesses..like

int sum=0;//outside the loop
sum+=noOfguesses;//inside the loop
avgNoOfGuesses=sum/noofgamesplayed;//outside the loop after it terminates
This article has been dead for over six months. Start a new discussion instead.