Missing brace somewhere and cant find

Im getting an error on visual studio that the left brace on the very top is unmatched at the end of the file. I am so confused and dont know what its talking about cause i have the ending brace at the end.

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
 #include <iostream>
using namespace std;
int main()
{
	int choice1, choice2, hours;
	const int UNDERGRAD = 1;
	const int GRAD = 2;
	const int YES = 1;
	const int NO = 2;
	cout << " Thank you for your interest in our project." << endl;
	cout << "Please answer the following questions by choosing the option that describes you." << endl;

	cout << "What is your academic status:" << endl;
	cout << "1. Undergraduate" << endl;
	cout << "2.Graduate" << endl;
	cout << "enter 1 or 2" << endl;
	cin >> choice1;
	if (choice1 == UNDERGRAD)
	{
		cout << "How many hours of programming have you taken?" << endl;
		cin >> hours;
		if (hours >= 12)
		{
			cout << "Congratulations, you are elgible to work on this project." << endl;
		}
		else {
			cout << "Unfortunately you are not eligible to participate in the project." << endl;
			cout << "Thanks for your time" << endl;
		}
	
	cin.get();

	cin.get();
	cin.get();
	return 0;
}
The } on line 36 is matched to the { on line 19. You code looks like 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
 #include <iostream>
using namespace std;
int main()
{
	int choice1, choice2, hours;
	const int UNDERGRAD = 1;
	const int GRAD = 2;
	const int YES = 1;
	const int NO = 2;
	cout << " Thank you for your interest in our project." << endl;
	cout << "Please answer the following questions by choosing the option that describes you." << endl;

	cout << "What is your academic status:" << endl;
	cout << "1. Undergraduate" << endl;
	cout << "2.Graduate" << endl;
	cout << "enter 1 or 2" << endl;
	cin >> choice1;
	if (choice1 == UNDERGRAD)
	{
		cout << "How many hours of programming have you taken?" << endl;
		cin >> hours;
		if (hours >= 12)
		{
			cout << "Congratulations, you are elgible to work on this project." << endl;
		}
		else {
			cout << "Unfortunately you are not eligible to participate in the project." << endl;
			cout << "Thanks for your time" << endl;
		}
	
	        cin.get();

	        cin.get();
	        cin.get();
	        return 0;
        }
closed account (DoLCX9L8)
There should be a } at line 30. That is all.
Hello iamyiyaj,

FYI I have found that using } // End of (whatever it matches) helps to keep things straight.

Hope that helps,

Andy

P.S. it looks like your IDE may have indented line 36 to match the if statement. That could easily through you off.
This is one of those things that is not carefully taught but should be mandatory two weeks plus 25% exam at the end.

Whenever you write an open brace:

1
2
  if (argc != 2)
  { 

You should immediately write a close brace:

1
2
3
  if (argc != 2)
  {
  } 

Only after that do you start adding stuff between braces.

1
2
3
4
5
  if (argc != 2)
  {
    std::cout << "Quiznak.\n";
    return 1; 
  }

This is pretty good advice for any kind of parenthetical pair. Modern IDEs will typically do it for you, even. If you type an open parenthesis, for example, it will automatically add a close parenthesis after the cursor insertion point:

    if   if () 

Type the stuff you want:

    if (argc != 2) 

And type the closing parenthesis as usual:

    if (argc != 2)  

Hope this helps.
Don't indent your code.
That superfluous white space is not understood by the compiler and so it's discarded.
Moreover, it may lead to confusion, as it happened in this case, because people do assign it a meaning. Then you have that dangerous situation where people and the compiler understand different things from the source code.

In order to avoid that, the solution is simple.
Don't indent your code, let your IDE do it for you.
Topic archived. No new replies allowed.