Random number generator, always generates same number

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cstdlib>

using namespace std;

int main ()
{
	int number = rand()%100;
	int guess = -1;
	int trycount = 0;
	while (guess != number && trycount < 8)
	{
		cout << "Please enter a guess: ";
		cin >> guess;
		if (guess < number) cout << "Too low" << endl;
		if (guess > number) cout << "Too high" << endl;
	}	
	if (guess == number) cout << "You guessed the number" << endl;
	else cout << "Sorry, you are wrong." << endl;
	return 0;
}


Number is always 83. I can't see what am I doing wrong here.
You're not seeding the random number generator.

http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
Another thing, only seed it once at the start of the program, and preferably seed it with the current system time.
Ok. Thanks.
Topic archived. No new replies allowed.