Help please

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;
}
Move entire block takeaguessYouFool() to outside main()
Last edited on
I've tried, I keep getting errors saying "cout is ambigous", from the cout in main function
Which line ? And update you code please
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>

using namespace std;
int const MAXTRIES = 3;
int const MAGICNUMBER = 5;
int Response;

char takeAGuessYouFool(int magicNumber)
{


}

int main()
{

	cout << "We are here to see if you can guess the magic number.\n\n";

	for (int tries = 1; tries > MAXTRIES; tries++)
	{
		int response;
			cout << "Please guess the magic number.  It's between 1 and 10 ";
		cin >> response;
		cout << takeAGuessYouFool(response);
	}

}
	
char takeAGuessYouFool(int magicNumber)
{
	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;
}



This is what I currently have, still working things
Remove line 32 and 33 change Response to magicNumber, change return type to string, rather than cout<< use return instead. In main use cout<<takeAGuessYouFool(response);
at line 9 replace {} with ;
Still getting some issues. I am extremely new to this, so bare with me as I only understand so much.

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
68
69
#include <iostream>
#include <string>

using namespace std;
int const MAXTRIES = 3;
int const MAGICNUMBER = 5;
int magicNumber;
char takeAGuessYouFool(int magicNumber);


int main()
{

	cout << "We are here to see if you can guess the magic number.\n\n";

	for (int tries = 1; tries < MAXTRIES; tries++)
	{
		int magicNumber;
		cout << "Please guess the magic number.  It's between 1 and 10 ";
		cin >> magicNumber;
		cout << takeAGuessYouFool(magicNumber);
	}
	system("pause");
	return 0;
}

char takeAGuessYouFool(int magicNumber)
{
	cout << "Please guess the magic number. It's between 1 and 10: ";
	cin >> magicNumber;

	switch (magicNumber)
	{
	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;
	default:
		cout << "DUDE!!! This is OUT OF BOUNDS!!!!\n";
	}
	system("pause");
	return 0;
}
Change function return value to string, remove line 67, 68 we dont need those here, also line 29 and 30 because it has done in main function. Next one change cout<< inside switch with return just like your expaination in first post, then remove '' after case, like case '1' to case 1, because you magicNumber is integer not char.
Last edited on
Topic archived. No new replies allowed.