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

In this exercise, you will modify the guessing game program from Figure 9-11 in

ID: 3604441 • Letter: I

Question

In this exercise, you will modify the guessing game program from Figure 9-11 in Chapter 9. Follow the instructions from starting C++ and viewing the Introductory15.cpp file, which is contained in either the Cpp8Chap10Introductiory15 Project folder or the Cpp8Chap10 folder. (Depending on your C++ development tool, you may need to open this exercise’s project/solution file first.) Modify the program so that it uses a void function to determine the random number. The program should ask the user for both the minimum and maximum random numbers that the void function should generate. The function call should pass that information to the void function. test the application appropriately.

Figure 9.11 from Ch9

#include "stdafx.h"

#include <iostream>

#include <ctime>

#include <cstdlib>

using namespace std;

int main()

{

int randomNumber = 0;

int numberGuess = 0;

//generate a random number from 1 through 10

srand(static_cast<int>(time(0)));

randomNumber = 1 + rand() % (10 - 1 + 1);

//get first 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;

return 0;

} //end of main function

Explanation / Answer

i have changed your program please check the changes : ---------------->>>>>>>>>>>>>>

#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

//void function to generate random number
void generateRandom(int f,int l,int *r){
*r = f+rand()%l;
}
int main()
{
int randomNumber = 0;
int numberGuess = 0;
int fNumber;//for storing and passing the first number to generate random
int sNumber;//second number to generate random value

//generate a random number from 1 through 10
srand(static_cast<int>(time(0)));
//randomNumber = 1 + rand() % (10 - 1 + 1);
//prompting user to enter least no.
cout<<" Enter The Least no. for guess game ";
cin>>fNumber;
//prompting for last number
cout<<"Enter the greatest no. for guess game ";
cin>>sNumber;

//calling to generate the number and store the value in randomNumber
generateRandom(fNumber,sNumber,&randomNumber);

//get first 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;

return 0;
} //end of main function

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