I need to initialize a set tries count as a constant value and implement it into the game as the max amount of tries for the game. Any help is appreciated. Thanks
#include <cstdlib>
#include <time.h>
#include <iostream>
usingnamespace std;
void printGreeting();
void game();
void printGoodbye();
int main()
{
printGreeting();
srand(time(0));
char answer;
do{
game();
cout << "Would you like to play again? (Y/N)" << endl;
cin >> answer;
}
while(answer == 'Y' || answer == 'y');
printGoodbye();
return 0;
}
void game(){
intconst number = rand() % 50 + 1;
intconst tries = 10;
int guess;
do
{
cout << "Enter your estimate: ";
cin >> guess;
if (guess < number)
cout << "TOO LOW!!" << endl;
elseif (guess > number)
cout << "TOO HIGH!!" << endl;
else
cout << "Your guess is right!" << endl;
}
while (guess != number);
}
void printGreeting(){
cout << "Hello and welcome to this number guessing game." << endl;
cout << "In this program you will be asked to guess a number from the given range in the amount of tries given to you by me" << endl;
cout << "You will guess from a range of 1-50 and will be given 10 tries." << endl;
}
void printGoodbye()
{
cout << "Thanks for playing my game!" << endl;
cout << "Good-bye and have a nice day!" << endl;
}
Line 25: Don't have tries as a const int, instead leave it as a int value.
After the if and else if statement, decrease the tries by 1 tries--
The while condition should be while (tries>0&&guess!=number)