That's good!
About the random number. Change this line:
int srand(time(NULL)); //seeds the generator
to this:
srand(time(NULL)); //seeds the generator
The first version is just a declaration, it tells the compiler the name of the function, and that it returns an integer. The seccond (corrected) version actually calls the function.
Regarding your code, it's fine no problems, well done.
But while we're here, sometimes it's worth looking if code can be shortened.
Start with this, which is ok:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
while (guess1 != num1)
{
if (guess1 < num1)
{
cout << "Too low.. try again." << endl;
cin >> guess1;
}
else if(guess1 > num1)
{
cout <<"Too high.. try again." <<endl;
cin >> guess1;
}
}
|
Though, the cin statement need be there just once.
... and, if the first test is false, the second must be true. If we also omit the braces, it reduces to this:
1 2 3 4 5 6 7 8 9
|
while (guess1 != num1)
{
if (guess1 < num1)
cout << "Too low.. try again." << endl;
else
cout << "Too high.. try again." << endl;
cin >> guess1;
}
|
Finally - the code formatting. When you are editing the post, click the
<>
button on the right.