The function is named "promptLoyola," and it has the following prototype. // This function will prompt the user for an integer in a particular range //***** YOU MUST IMPLEMENT THIS FUNCTION ***** int promptLoyola ( string, 7/ Tell the user what sort of number is needed, or how it will be used int, int, int, int // The lowest value to allow // The highest value to allow // How many tries the user gets // The default value if the user fails on every try he makes ); You must implement the function along the following steps: 1. The function has five parameters, but none have names in the prototype. To use them you must give each parameter a name that you will use in the body of the program. 2. Declare an int variable to hold the user's response 3. Type out the message in the first parameter ("Tell the user..") 4. Tell the user that the input must be in the range specified by the second and third parameters ("lowest value.." and "highest value.") 5. Get an int value from the user and put it into the variable (yes, go ahead and use cin) 6. If the user's input is in range, return the variable 7. Otherwise count down the number of tries remaining as given in the fourth parameter ("How many tries..") 8. If the user exceed the tries without entering a number in range, return the default value that is in the fifth parameter ("The default value if..")
C++ Language
The C++ File To Be Revised; The file centered around in this asisgnment
#include <iostream>
using namespace std;
const string PROGRAM_NAME = "test-prompt-loyola";
const int LOW_RANDOM_VALUE = 20, HIGH_RANDOM_VALUE = 25;
// This function will prompt the user for an integer in a particular range
//***** YOU MUST IMPLEMENT THIS FUNCTION *****
int promptLoyola (
string, // Tell the user what sort of number is needed, or how it will be used
int, // The lowest value to allow
int, // The highest value to allow
int, // How many tries the user gets
int // The default value if the user fails on every try he makes
);
int main () {
cout << "Welcome to " << PROGRAM_NAME << endl;
int gotRandom = LOW_RANDOM_VALUE + (rand () % (1 + HIGH_RANDOM_VALUE - LOW_RANDOM_VALUE));
cout << "Test A:\n";
int userGuess = promptLoyola ("Guess the random number!", LOW_RANDOM_VALUE,
HIGH_RANDOM_VALUE, 4, -1);
if (userGuess == -1) { cout << "You didn't want to guess a number?" << endl; }
else {
if (userGuess == gotRandom) {
cout << "You guessed the right number!\n";
} else {
cout << "Sorry, the number was " << gotRandom << endl;
}
}
cout << "Test B:\n";
int userPrefTemp = promptLoyola ("What is your most comfortable temperature? ",
20, 120, 3, -1);
if (userPrefTemp == -1) {
cout << "No answer I guess\n";
} else if (userPrefTemp < 67) {
cout << "Sorry, but " << userPrefTemp << " is too cold for me!\n";
} else if (userPrefTemp > 85) {
cout << "I don't like it that hot!\n";
} else {
cout << "I could go with that...\n";
}
cout << "Test C:\n";
userGuess = promptLoyola ("Guess another number", 1, 1, 1, -1);
if (userGuess == 1) { cout << "Great!\n"; }
else { cout << "no guess...\n"; }
cout << "Test D:\n";
userGuess = promptLoyola ("Zero tries?", 10, 20, 0, 5);
if (userGuess == 5) { cout << "No input\n"; }
else { cout << "Got input " << userGuess << endl; }
cout << "Thank you for using " << PROGRAM_NAME << endl;
return 0;
}
________
This file does not compile successfully; it will give an error like "Undefined symbols..." It gives this error because there is a function that is called by the program, but there is no implementation for the function in the program. The function is named "promptLoyola."
YOUR ASSIGNMENT IS TO WRITE THE FUNCTION AND MAKE IT WORK.
You will see that test-prompt-loyola.cpp already has a main function. It has four tests (A, B, C, D) in which it runs promptLoyola in various ways. You do not need to make any changes to the main function.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images