couple questions for very small random number program
Hey I am trying to make a smal random number game just for practice and have 2 questions. First I'm wondering if im generating the random number (between 1 and 100) the correct way. Second I am wondering how to loop this program (preferably with a for loop) so it will ask more than 1 time and then produce the answer, if the answer isnt correct then I obviously want it to ask then answer again. I am not sure you can use a for with the if-else? Anyways any help will be appreciated, thanks.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main ()
{
int guess;
double random;
int i;
cout << " I'm guessing of a number between 1 and 100 can you guess it?\n";
cin >> guess;
srand(time(NULL));
random = rand() % (100 + 1);
if (random > guess)
cout << "Guess was too big\n";
else if (random < guess)
cout << "Guess was too small\n";
else if (random == guess)
cout << "You got it!\n";
system ("pause");
return 0;
}