So I have this question I am suppose to answer, and the solution is evading me. I was presented with this word file to create a program.
0----------------------------------------------------------------------0
[1] Assign a global const integer named MAGICNUMBER at the beginning of the program.
• You can set this const integer to any value you want between 1 and 10.
[2] Assign a global const integer named MAXTRIES at the beginning of the program and make it equal to 3.
[3] Create a function named “takeAQuessYouFool( )” (this will be the “called” function) that will:
• Return a string.
• The function body will also have a local string variable named: “response”.
• Take in an integer named “magicNumber” via its parameter list.
• Use that integer (named “magicNumber”) inside the function body to test it using a switch statement.
• For the cases inside the switch body, where “magicNumber” is greater than your “MAGICNUMBER” value, have it set the string variable (e.g., “response” ) to the following value:
"Uh, uh, uh!!! Too high!!”.
• For the cases inside the switch body, where “magicNumber” is less than your “MAGICNUMBER” value, have it set the string variable (e.g., “response” ) to the following value:
"Uh, uh, uh!!! Too LOW!!”.
• For the cases inside the switch body, where “magicNumber” is EQUAL TO your “MAGICNUMBER” value, have it set the string variable (e.g., “response” ) to the following value:
"EUREKA!!! You GUESSED IT!!”.
• For the cases inside the switch body, where “magicNumber” is OUTSIDE the RANGE, (e.g., greater than 10 or less than 1) have it set the string variable (e.g., “response” ) to the following value:
"DUDE!!! This is OUT OF BOUNDS!!!!”.
• Have the function “takeAQuessYouFool( )” return its local string variable named “response”.
[4] Let main be the calling program.
The main function should have a local variable of type “int” named “magicNumber”.
The main function shall also do the following:
• first, print the following statement:
“We are here to see if you can guess the magic number.” <newline><newline>
• Below that statement, Create a “for” loop that will increment from 1 to MAXTRIES (which is the integer value “3” you declared as a global const).
• Inside the body of the “for” loop, you will have the following statements:
[a] First print the following statement:
"Please guess the magic number. It's between 1 and 10: "
[b] “cin” the “magicNumber” variable that the user inputs.
[c] then, use “cout” to call the “takeAQuessYouFool( magicNumber )” function so that it can print out the
string it returns to the cout statement.
[d] Close up the “for” loop.
• Finally, after the “for” loop block, have main print out the following statement:
"Thank you for being a good sport!!” <newline><newline>
0--------------------------------------------------------------------------0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <string>
int takeAGuessYouFool();
using namespace std;
const int MAGICNUMBER = 5;
const int maxtries = 3;
int main()
{
char Response = ' ';
cout << "We are here to see if you can guess the magic number.\n\n";
int takeAGuessYouFool();
{
cout << "Please guess the magic number. It's between 1 and 10: ";
cin >> Response;
if ((Response == '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'))
{
switch (Response)
{
case '1':
cout << "Uh, uh, uh!!! Too low!!\n";
break;
case '2':
cout << "Uh, uh, uh!!! Too low!!\n";
break;
case '3':
cout << "Uh, uh, uh!!! Too low!!\n";
break;
case '4':
cout << "Uh, uh, uh!!! Too low!!\n";
break;
case '5':
cout << "EUREKA!!! You GUESSED IT!!\n";
break;
case '6':
cout << "Uh, uh, uh!!! Too high!!\n";
break;
case '7':
cout << "Uh, uh, uh!!! Too high!!\n";
break;
case '8':
cout << "Uh, uh, uh!!! Too high!!\n";
break;
case '9':
cout << "Uh, uh, uh!!! Too high!!\n";
break;
case '10':
cout << "Uh, uh, uh!!! Too high!!\n";
break;
}
}
else
{
cout << "DUDE!!! This is OUT OF BOUNDS!!!!\n";
}
}
system("pause");
return 0;
}
|