I have been having a huge issue with my compiler. so please bear with me.
The code that I am to write is that of a high low game.
General Specification: The High Low Guessing Game should begin by prompting the
user for his or her guess to a secret number. The computer should generate a secret number using the rand() random number function.
For each guess the computer should display an appropriate message, Too Low, or Too High.
The computer should continue giving High/Low hints until the secret number is guessed.
The computer should keep track of how many guess it took to guess the secret number.
The game should conclude with one of three custom messages based on multiple
alternative selection control. For example -
[1 to 4 guesses] You are an above average player. You must
be psychic.
[5 to 7 guesses] You are an average player. Keep
practicing.
[More than 7 guesses] You are a below average player.
Don’t quit your day job.
You application should conclude with a query-control loop that asks if the player wants
to ‘Play Again? Y/N:’
This is what I have: (Am I on the right Track?!)
#include <iostream>
#include <cstdlib>
#include <ctime>
int main(void) {
srand(time(NULL));
while(true) {
int number = rand() % 99 + 2;
int guess;
int tries = 0;
char answer; //
while(true)
cout << "Enter a number between 1 and 100";
cin >> guess;
cin.ignore();
if(guess > number) {
cout << "Too high! Try again.\n";
} else if(guess < number) {
cout << "Too low! Try again.\n";
} else {
cout<<"Congratulations!! " << std::endl;
cout<<"You got the right number in " << tries
<< "Tries!\n";
if (guess >= 4) {
cout << "You are an above average player. You
must be psychic."}
else if (guess <=7) {
cout << "You are an average player. Keep
Trying." }
else (guess >7) {
cout << "You are an below average player."}
while(true) {
cout << "Would you like to play again (Y/N)? ";
cin >> answer;
cin.ignore();
while (true) {
int number = rand() % 99 + 2;
int guess;
int tries = 0;
char answer;
while (true)
cout << "Enter a number between 1 and 100";
cin >> guess;
cin.ignore();
if (guess > number) {
cout << "Too high! Try again.";
}
else if (guess < number) {
cout << "Too low! Try again.";
}
else {
cout << "Congratulations!! " << endl;
cout << "You got the right number in " << tries << "Tries!" << endl;
if (guess >= 4) {
cout << "You are an above average player. You must be psychic.";
}
else if (guess <= 7) {
cout << "You are an average player. Keep Trying.";
}
else (guess > 7) {
cout << "You are an below average player.";
}
while (true) {
cout << "Would you like to play again (Y/N)? ";
cin >> answer;
cin.ignore();
if (answer == 'n' || answer == 'N' || answer == 'y' || answer == 'Y') {
break;
}
else {
std::cout << "Please enter \'Y\' or \'N\'...\n";
}
}
if (answer == 'n' || answer == 'N') {
cout << "Thank you for playing!";
break;
}
else {
cout << "\n\n\n";
}
}