Beginner question

Hi,
Sorry I'm trying to work through some of the beginner problems which are posted here http://www.cplusplus.com/forum/articles/12974/
I'm doing the "Bracketing search" question and my 'code' is below...the trouble is I don't get a different random number each time...i.e. the answer is the same every time I run the program :(. I'm sure the solution is pretty simple but it's annoying me nonetheless.

Thanks!

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
  #include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain()
{int a, b;
cout<<"Guess the number!\n";
cin>>b;
a= rand() % 100;
if (b!=a);
{do
{if (b>a)
		{cout<<"Too high! Guess again\n";
cin>>b;}
	else if (b<a)
		{cout<<"Too low! Guess again\n";
cin>>b;}}
while (b!=a);
	
if (b==a)
{cout<<"Congratulations, you are correct!\n";}
}

	return 0;
}
Include headers <cstdlib> and <ctime> and use

std::srand( ( unsigned int )std::time() );

in the very beginning of the program.
I've put in the headers but what about this 2nd line? Where does that go? In the "using namespace.." bit?

And why does it not generate a new random number each time?
Ok, I found this
http://www.cplusplus.com/reference/cstdlib/rand/

thanks for your help
Topic archived. No new replies allowed.