Need help running my program

i need help with my first project in c++. I think i have the content bu yet i can't find where to put a close brace }....please help me go over my code

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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int guess;
	int upperBound;
	int lowerBound;
	int range;

	unsigned int seed = static_cast<unsigned int>(time(0));
	srand(seed);
	char c;

	bool done = false;
	do {
		bool found = false;
		upperBound = 101;
		lowerBound = 1;
		do {
			range = upperBound - lowerBound;
			guess = lowerBound = (rand() % (range));
			if (range > 0)
			{
				char response;
				cout << "Hey..is this your number? (lhy) " << guess << endl;
				cin >> response;
				
				switch (response) {
				case 'l':
				case'L' :
					cout << "Too low" << endl;
					lowerBound = guess + 1;
					break;

				case 'h':
				case'H' :
					cout << "Too high" << endl;
					upperBound= guess - 1;
					break;
				case 'y':
				case 'Y':
					cout << "Yes!" << endl;
					found = true;
					break;
				default:
					cout << " Does not compute" << endl;
					break;
				};
			}
			else {
				cout << "Your number must be: " << lowerBound << endl;
				found = true;
			}
			bool done = false;
			do {
				cout << "do you want to play again? (y/n)" << endl;
				cin >> c; 
				if (( c == 'n') || (c =='N'))
				{done = true;
				cout << "Thanks for playing" << endl;
				}
				else{
					cout << " Great pick another number!" << endl;
				}
			} while (!found);

		cout << "Press any key and <Enter> to continue..." << endl; 
		char c;
		cin >> c;

		return 0;
		}
	



[code]
[/code]
Last edited on
One, please put your code in code tags. Click the <> symbol on the right or do it manually by adding the tags yourself. I can't see line numbers or indentation, but it looks like your first do loop is missing a closing brace, and most of them don't even have conditions. Lastly, what's so hard about finding a missing closing brace? Your compiler should tell you where the problem is, I think you could've figured this one out on your own :/
You are missing two closing brackets here. You always have to have the same number of opening ones as closing ones.

Check your indents. We can see that you have two tabs to go to get back to the left side.

Your switch is fine,
Your if (range>0) is also fine,
Your innermost do/while (!found) is fine,
Your other do/whiles do not have an ending condition.

Try this:
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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int guess;
	int upperBound;
	int lowerBound;
	int range;

	unsigned int seed = static_cast<unsigned int>(time(0));
	srand(seed);
	char c;

	bool done = false;
	do {
		bool found = false;
		upperBound = 101;
		lowerBound = 1;
		do {
			range = upperBound - lowerBound;
			guess = lowerBound = (rand() % (range));
			if (range > 0)
			{
				char response;
				cout << "Hey..is this your number? (lhy) " << guess << endl;
				cin >> response;
				
				switch (response) {
				case 'l':
				case'L' :
					cout << "Too low" << endl;
					lowerBound = guess + 1;
					break;

				case 'h':
				case'H' :
					cout << "Too high" << endl;
					upperBound= guess - 1;
					break;
				case 'y':
				case 'Y':
					cout << "Yes!" << endl;
					found = true;
					break;
				default:
					cout << " Does not compute" << endl;
					break;
				};
			}
			else {
				cout << "Your number must be: " << lowerBound << endl;
				found = true;
			}
			bool done = false;
			do {
				cout << "do you want to play again? (y/n)" << endl;
				cin >> c; 
				if (( c == 'n') || (c =='N'))
				{done = true;
				cout << "Thanks for playing" << endl;
				}
				else{
					cout << " Great pick another number!" << endl;
				}
			} while (!done);
		} while (!found);

		cout << "Press any key and <Enter> to continue..." << endl; 
		char c;
		cin >> c;
	} while (!done);
return 0;
}


Note there is still one more problem here, you define bool done twice. Try using different names.
Stewbond, try not to give out so much code, it doesn't help the person in the end!
Last edited on
I am trying to write the same program,
but this code doesn't seem to work right and I am having the same problem.

When you enter h l or y it just ends the game,
please help!!
Please show us your code, thanks.
Topic archived. No new replies allowed.