#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
usingnamespace std;
int main(int argc, char *argv[])
{
int i =1;
int magic; //computer-generated number
int guess; //user input
magic = srand(time(0)) ; //get a random nuber (within the specified type)
do{
cout << "Guess the magic number: ";
cin >> guess;
if(guess == magic)
{
cout << "Correct! The magic number was " << magic << endl;
cout << "You needed " << i << " tries to guess the number\n";
}
else
{
cout << "Incorrect..\n";
if(guess > magic) cout << "Your guess was too high\n";
else cout << "Your guess was too low\n"; i++;
}
} while (guess != magic);
system("PAUSE");
return EXIT_SUCCESS;
}
I'm sure it's something really simple that I'm overlooking. I've looked at several solutions but, it seems to apply to that specific code. Please help!
Thank you so much! I knew it was something simple like that. srand turns the engien on, and rand actually drives (to use an analogy of sorts).
So then, what are some other places besides time that srand can seed. could I use an algebraic equation based on user input (variables x, y, etc)? something like srand(x +y)?