I commented it for you, the srand() function will seed to your rand() function algorithm and make sure its always a random number generated. Make sure to only call srand() no more than once in your program.
#include <iostream>
#include <ctime>
usingnamespace std;
int main(void)
{
srand(time(0));
int MAX_RANGE = 100; // The max range from 1-100 of rand();
int Oliver = rand() % MAX_RANGE + 1; //Initializes Oliver to = rand() with the set MAX_RANGE starting from 1
int User_guess;
//Basically will run the program over and over until you guess correctly.
do{
cout << "What is my number: ";
cin >> User_guess;
if(User_guess == Oliver)
cout << "You guessed correctly!\n";
elseif(User_guess < Oliver)
cout << "You guessed to low! Try again!\n";
elseif(User_guess > Oliver)
cout << "You guessed to high! Try again!\n";
}while(User_guess != Oliver);
cin.get(); //Dont use system, just use cin.get() if you want a pause.
cin.get();
return 0;
}
Please don't make such statements if you don't know what you're talking about.
emyr666 is right.
When you are going to use functions from a header, you have to include it (obviously).
It doesn't count if another header (like <iostream>) happens to include <cstdlib> by chance. That's an implementation detail and it is nothing you are allowed to rely on. It might just as well change in the next update to your standard library implementation.