random number guessing game

I need help with an assignment for a class.Im supposed to write a program where the program picks a number between 1 and 1000 and you have to guess the number.After you guess the number you have the option of if you want to play again or not meaning its supposed to display "Would you like to play again? enter y/n"

this is what i have:
#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
srand(time(0));
int number=rand()%1000+1;;
int guess;
cout<<"Im thinking of a number between 1-1000. Take a guess: ";
cin>>guess;

while(guess!=number)
{
if(guess>number)
{
cout<<"Too high,Guess again: ";
cin>>guess;
}
if(guess<number)
{
cout<<"Too low,Guess again: ";
cin>>guess;
}
}
if(guess=number)
{
cout<<"Congrats!! You got it.";
}

return 0;
}

this doesnt work right and i have no idea how to do the play again feature.Anybody who knows how to do this,Please help me..........
Post your question only at one forum next time, most people look at both beginner and general
Try this:

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
#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
	srand(time(0));
	int number;
	int guess;
	char option;
	do {
		number = rand() % 10 + 1;
		cout<<"Im thinking of a number between 1-1000. Take a guess: ";
		cin>>guess;
		while(guess!=number)
		{
			if(guess>number)
			{
				cout<<"Too high,Guess again: ";
				cin>>guess;
			}
			if(guess<number)
			{
				cout<<"Too low,Guess again: ";
				cin>>guess;
			}
		}
		if(guess=number)
		{
			cout<<"Congrats!! You got it." << endl;
		}
		cout << "Would you like to play again? enter y/n ";
		cin >> option;
	} while (option == 'y');
	return 0;
}
Topic archived. No new replies allowed.