This program is a high-low guessing game where a random number is generated and the user has 6 attempts to guess the number. I only copied my main function and the definition of the DrawNum and GetGuess functions, will post more if asked/needed. My goal is to have the DrawNum function return the random number and call the DrawNum function in the GetGuess function (if that is even the most efficient way of doing it). The function builds fine, but when I run the program I get Run-Time Check Failure #3 - the variable 'MaxNum' is being used without being initialized.
int main ()
{
int money;
int bet;
int guesses;
unsigned int seed = 0;
srand(static_cast<unsigned>(time(NULL))); //get a value for the time from the computer's clock and with
srand (seed); //it calls srand to initialize "seed" for the rand() function
PrintHeading (); //Prints output heading
GetBet (money, bet);
GetGuess ();
CalcNewMoney (money, bet, guesses);
bool PlayAgain ();
}
int DrawNum (int max)
{
double x = RAND_MAX + 1.0; /* x and y are both auxiliary */
int y; /* variables used to do the */
/* calculation */
y = static_cast<int> (1 + rand() * (max / x));
return (y); /* y contains the result */
}
int GetGuess ()
{
int guess; //user's guess
int guesses; //number of Guesses
int MaxNum;
int RandNum;
RandNum = DrawNum (MaxNum);
for (int guesses = 1; guesses <= 6; guesses++)
{
cout << "Guess " << guesses << ":" << endl;
cin >> guess;
if (guess > RandNum)
{
cout << "Too high... " <<endl;
}
else if (guess == RandNum)
{
cout << "Correct!" << endl;
}
else
{
cout << "Too low... " << endl;
}
}
return (guesses);
}