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

Font Paragraph CMPSC 125: C++ Programming Programming Project Assignment Due: Ju

ID: 3906985 • Letter: F

Question

Font Paragraph CMPSC 125: C++ Programming Programming Project Assignment Due: Jun. 25, 11:59 am Program Description: This assignment focuses on while loops and random numbers. Turn in a file named Lab4_yourFirstName.cpp. Your program allows the user to play a game in which the program thinks of a random integer and accepts guesses from the user until the user guesses the number correctly. After each incorrect guess, you will tell the user whether the correct answer is higher or lower The below shows one sample execution of your program. Your output will differ depending on the random numbers chosen and user input typed, but the overall output structure should match that shown below I am thinking of a number between 1 and 100 Your guess? S0 [Enterl It's lower Your guess? 25 [Enterl s higher Your guess? 35 [Enter) s lower Your guess? 30 [Enterl It's higher Your guess? 32 (Enter] It's lower Your guess? 31 [Enter)] ou got it right in 6 guesses Do you want to play again? Y[Enterl I am thinking of a number between 1 and 100 Your guess? 50 [Enterl It's higher Your guess? 75 [Enter our guess? 65 [Enter our guess? 64 [Enterl ou got it right in 4 guesses Do you want to play again? YiEnter Iam thinking of a number between 1 and 100

Explanation / Answer

If you have any doubts, please give me comment...

#include<iostream>

#include<iomanip>

#include<cstdlib>

#include<ctime>

using namespace std;

int main(){

srand(time(NULL));

int total_games = 0, tot_guesses = 0, best_game;

char playAgain;

do{

int randNum = rand()%100+1;

cout<<endl<<"I am thing of a number between 1 and 100"<<endl;

int userNum, no_guesses = 0;

while(1){

cout<<"Your guess? ";

cin>>userNum;

no_guesses++;

if(userNum==randNum){

cout<<"You got it right in "<<no_guesses<<" guesses!"<<endl;

if(best_game>no_guesses){

best_game = no_guesses;

}

break;

}

else if(userNum < randNum)

cout<<"It's higher"<<endl;

else

cout<<"It's lower"<<endl;

}

if(best_game==0)

best_game = total_games;

total_games++;

tot_guesses += no_guesses;

cout<<"Do you want to play again? ";

cin>>playAgain;

}while(playAgain=='y'||playAgain == 'Y');

cout<<setprecision(1)<<fixed;

cout<<" Statics Result: "<<endl;

cout<<"Total games = "<<total_games<<endl;

cout<<"Total guesses = "<<tot_guesses<<endl;

cout<<"Guessses/game = "<<((double)tot_guesses/total_games)<<endl;

cout<<"Best game ="<<best_game<<endl;

return 0;

}