How do I fix the randomize error? #include<iostream> using namespace std; #defin
ID: 3554300 • Letter: H
Question
How do I fix the randomize error?
#include<iostream>
using namespace std;
#define max 99 // Maximum number for the game
int main()
{ // Specification of variables
int random, compGuess, userGuess, guess, low, high;
char answer;
cout << " GUESSING GAME ";
randomize();
while(1)
{
random = 1 + max* (rand()/(RAND_MAX+1.));
cout << " I have selected a number... ";
for(userGuess=1; ; userGuess++)
{
cout << " Your guess: " << userGuess;
cin >> guess;
if(guess < 1 || guess > max) return 0;
if(guess == random)
{
cout << "Correct!";
break;
}
if(guess < random)
cout << guess << " is too small.";
else
cout << guess << " is too big.";
}
cout << " Please select a number and press return when ready. ";
getchar();
random = 1 + max* (rand()/RAND_MAX+1.); // Random guess
for(compGuess=1; ; compGuess++)
{
cout << "My guess: " << compGuess << ". Too small (<), too big (>), or correct (=).";
cin >> answer;
if(answer == '=') break;
if(answer == '>')
{
if(compGuess == 1) low = 1;
high = random-1;
}
else if (answer == '<')
{
if(compGuess == 1) high=max;
low = random+1;
}
else return 0; // Incorrect answer
random = (low + high)/2; // New guess
if(low > high)
{
cout << " You are cheating and the game is over. ";
return 0;
}
}
cout << " Results: You: " << userGuess << " I: " << compGuess;
if(userGuess == compGuess)
cout << "It's a tie.";
else
cout << ((userGuess < compGuess) ? "You " : "I ") << "win this time. ";
}
}
Explanation / Answer
include stdlib.h header file for randomise function...........
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.