But I have the following problem... I'm trying to make a small program in which I type in a random number anywhere between 1 and 10 and the computer has to guess it by throwing out a randomly generated number with time seed random % 10 + 1.
Now, as I run the program, it does loop the random guess and all of it's if conditions, but it seems to produce the same random number over-and-over-and-over.... despite the fact that I specifically told the program to take a truely random number.... Could you have a look at it?
There is no compilation errors, what so ever.
Code: Select all
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int randomGuess = rand() % 10 + 1;
int tries = 0, myInput;
cout << "\n\tWelcome to GUESS MY NUMBER!\n";
cout << "\tPick a number in between 1 and 10\n";
cout << "\tand I will try to guess it!\n\n";
cout << "Please enter a number between 1 and 10: ";
cin >> myInput;
do{
cout << "My guess is " << randomGuess << ".\n";
++tries;
if(randomGuess < myInput)
{
cout << "I guessed too low!\n\n";
}
if(randomGuess > myInput)
{
cout << "I guessed too high!\n\n";
}
}while(randomGuess != myInput);
cout << "I think I guessed it right in " << tries << " guesses!\n";
return 0;
}
Code: Select all
cout << "My guess is " << (randomGuess = rand() % 10 + 1)<< ".\n";