Right now, your only loop is
1 2
|
for(int index=0; index<20; index++)
random_integer = (rand()%10)+1;
|
which just assigns a random integer to
random_integer 20 times in a row (each time overwriting the previous value).
After that, you get an input from the user, compare it with a few values, and exit.
You need to loop around the code that gets the input and prints the messages, not the code that generates the random number.
It should suffice to put a
do {
before the
cin >> guess;
and a
} while (guess != random_integer);
after the
1 2 3 4 5
|
else
{
cout << "Nope! Try again!" << endl;
tries += 1;
}
|
.
On a side note, what compiler do you use?
iostream.h is long deprecated -- use
#include <iostream>
(no .h) instead.
If that doesn't compile for you, then you really need to get a better compiler.
Also, you would normally have to
#include <ctime>
to use the
time function.
(Just saying)