Unequal Brackets and Illegal Default???

Hey everyone,

I'm relearning C++ for the first time in a few years. I need some help. I'm using Microsoft Visual C++ 2008.

I'm getting the error messages
1
2
>c:\users\home\documents\visual studio 2008\projects\secondproject\secondproject\main.cpp(59) : error C2047: illegal default
1>c:\users\home\documents\visual studio 2008\projects\secondproject\secondproject\main.cpp(72) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\home\documents\visual studio 2008\projects\secondproject\secondproject\main.cpp(6)' was matched


when I try to compile

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>
using namespace std;

int main(void)

{
	system("TITLE Calculator");
	system("COLOR 2");
	system("pause");

	char cChar;
	double dfirstnumber;
	double dsecondnumber;
	char cDoagain;

do
{
	system("CLS");
	cout << "Please enter the first number you would like to use: " 
		 << endl;
	cin >> dfirstnumber;
	cout << "Please enter the desired operation" 
		 << endl
		 << "+,-,* and / are acceptable operations";
	cin >> cChar;
	cout << "Please enter the second number you would like to use: "
		 << endl;
	cin >> dsecondnumber;

	switch (cChar)
	{

		case '+' :
		cout << "The result is: " << (dfirstnumber + dsecondnumber)
		<< endl;
		break;

		case '-' :
		cout << "The result is: " << (dfirstnumber - dsecondnumber)
		<< endl;
		break;

		case '*' :
		cout << "The result is: " << (dfirstnumber * dsecondnumber)
		<< endl;
		break;

		case '/' :
		if(dsecondnumber == 0)
		{ cout << "That is an invalid operation" <<endl;
		}
		else
		{
		cout << "The result is: " << (dfirstnumber / dsecondnumber)
		<< endl;
		break;
	}
}
	

		cout << "Would you like to try again? Y/N" <<endl;
		cin >> cDoagain;


		while (cDoagain == 'Y' || cDoagain == 'y');
		system ("PAUSE");
		return 0;
}


I've tried matching brackets, but I only get more error messages when I have an equal amount.

Also, I don't know why the default is illegal. I've tried for hours to fix this. Can anyone help me?
closed account (z05DSL3A)
It looks like the brace on line 58 should be on line 65.
}while (cDoagain == 'Y' || cDoagain == 'y');

Edit:
there is one missing: ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
		else
		{
		    cout << "The result is: " << (dfirstnumber / dsecondnumber)
		    << endl;
		    break;
	        } //end of else
        }//end of switch
	

		cout << "Would you like to try again? Y/N" <<endl;
		cin >> cDoagain;


}while (cDoagain == 'Y' || cDoagain == 'y');
		system ("PAUSE");
		return 0;
Last edited on
You did not close the else{ on line 53.
put } on line 56.
or maybe not...

I suppose the 'default' is illegal due to this, though there is no 'default' in the code you posted...

Also, use proper indentation to avoid errors like this
1
2
3
4
5
6
7
8
int main(){
    do{
        switch(){
            case:
                break;
        }
    }
}
Last edited on
Ctrl+A and then Ctrl+K & Ctrl+F will help format your code with VS automatically.
closed account (z05DSL3A)
Also, use proper indentation to avoid errors like this

or
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    do
    {
        switch()
        {
            case:
                break;
        }
    }while(/**/)
}

It is easier to see matching braces if you 'stack' them
THANK YOU ALL!!! All comments were helpful (from formatting to execution). I'm still in the stage where I need to determine what brackets go where...it's been a while since I've done this.

Program ran flawlessly! Many thanks!
Topic archived. No new replies allowed.