Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the program so that it allows the user to make only four incorrect guesse

ID: 3681848 • Letter: M

Question

Modify the program so that it allows the user to make only four incorrect guesses.

//Lab9-1.cpp - simulates a number guessing game //Created/revised by on <3-23-2016> #include #include //#include using namespace std; int main() { //declare variables int randomNumber = 0; int numberGuess = 0; //generate a random number from 1 through 10 srand(static_cast(time(0))); randomNumber = 1 + rand() % (10 - 1 + 1); //get first number guess from user cout << "Guess a number from 1 through 10: "; cin >> numberGuess; while (numberGuess != randomNumber) { cout << "Sorry, guess again: "; cin >> numberGuess; } //end while cout << endl << "Yes, the number is " << randomNumber << "." << endl; system("pause"); return 0; } //end of main function

Explanation / Answer

Hi,

#include
#include
using namespace std;
int main() {
//declare variables
int randomNumber = 0;
int numberGuess = 0;
//generate a random number from 1 through 10
srand(static_cast(time(0)));
randomNumber = 1 + rand() % (10 - 1 + 1);
//get first number guess from user
cout << "Guess a number from 1 through 10: ";
cin >> numberGuess;
int count=1
while (numberGuess != randomNumber&&count==4) {
cout << "Sorry, guess again: ";
cin >> numberGuess;
count++;
}
//end while
cout << endl << "Yes, the number is " << randomNumber << "." << endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote