Number guessing game help

How do I allow the program to be replayed I have bool, and the conditionals, but it is not functioning?
Also how would I keep track of the previous tries, and display the lowest one, or "low score"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
 int numberofguesses=0;
 bool playagain=true;
 char answer;
int guesses;
	int num;
	int guess;
	bool isGuessed;
	srand(time(0));
	num=rand()%1000;
	isGuessed=false;
	while(!isGuessed and playagain==true){
 
	cout<<"Enter an integer greater than or equal to 0 and less than 1000"<<endl;
	cin>>guess;
	numberofguesses++;
	if(guess>1000 or guess<=-1)
	{
		cout<<"Please enter proper number, your number is out of range"<<endl;
		break;
	}

	if(guess==num)
	{
		cout<<"You guessed the correct number."<<endl;
		isGuessed=true;
		cout<<"It took you "<<numberofguesses<<" "<<" tries to guess the correct number!"<<endl;
		cout<<"Would you like to play again? Enter Y/N"<<endl;
		cin>>answer;
		if(answer='N')
		{
		
			cout<<"Thanks for playing!"<<endl;
	
		}
	    else if(answer='Y')
		{
			playagain=false;
		}
		
	}

	 else if (guess<num)
	cout<< "Your guess is lower than the number. Try again."<<endl;
	
	else
	cout<< "Your guess is higher than the number. Guess again!"<<endl;

}
}
Repeat post, marking as solved.
Last edited on
Topic archived. No new replies allowed.