{} errors, not sure why!

Okay people, basically this is coursework which has to be in on this Thursday.
It's nearly finished, but I keep getting errors with my "{}"'s.
I really don't know why - I've spent ages going through my code and trying to see what's wrong, but it hasn't worked at all.


Any help with this would be greatly appreciated!

Thanks in advance,
Tom Yallop

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "stdafx.h"
#include <math.h>
#include <iostream>
#include <vector>
#include <conio.h>
using namespace std;
void circle ();
void triangle ();
void rectangle ();
int main()

{
int menuChoice = 0;
cout << "Do you require:-" << endl;
cout << "1. Circle" << endl;
cout << "2. Triangle" << endl;
cout << "3. Rectangle" << endl;
cout << "4. Quit" << endl;
cout <<" " << endl;
cin >> menuChoice;
cout << " " << endl;


if (menuChoice == 1)
{
circle ();
}

else if (menuChoice == 2)
{
triangle ();
}

else if (menuChoice == 3)
{
rectangle ();
}

else if (menuChoice == 4)
{
cout << "Goodbye" << endl << endl;
}

// CIRCLE!!!
void cicrle ()
{
double circumference = 0, area = 0, diameter = 0, radius = 0, pi = 0, menuChoice1 = 0;

cout << "Please choose an option: " << endl;
cout << "1. Circumference" << endl;
cout << "2. Area" << endl;
cout << " " << endl;
cin >> menuChoice1;
cout << " " << endl;


if ( menuChoice1 == 1 )
{
cout << "Please enter the diameter of the circle: " << endl;
cin >> diameter;
cout << " " << endl;
cout << "Please enter the value of Pi you wish to use: " << endl;
cin >> pi;
cout << " " << endl;
circumference = diameter*pi;
cout << "The circumference is: " << endl;
cout << circumference << endl;
cout << " " << endl;
}

else if ( menuChoice1 == 2 )
{
cout << "Please enter the radius (half the diameter) of the circle: " << endl;
cin >> radius;
cout << " " << endl;
cout << "Please enter the value of Pi you wish to use: " << endl;
cin >> pi;
cout << " " << endl;
radius = radius * radius;
area = radius * pi;
cout << "The area is: " << endl;
cout << area << endl;
cout << " " << endl;
}
}
//TRIANGLE
void triangle ()
{
double perimeter = 0, area = 0, sideA = 0, sideB = 0, sideC = 0, height = 0, base = 0, menuChoice2 = 0;

cout << "Please choose an option: " << endl;
cout << "1. Perimeter" << endl;
cout << "2. Area" << endl;
cout << " " << endl;
cin >> menuChoice2;
cout << " " << endl;

if ( menuChoice2 == 1 )
{
cout << "Please enter the length of side A:" << endl;
cin >> sideA;
cout << " " << endl;
cout << "Please enter the length of side B:" << endl;
cin >> sideB;
cout << " " << endl;
cout << "Please enter the length of side C:" << endl;
cin >> sideC;
cout << " " << endl;
perimeter = sideA + sideB + sideC;
cout << "The perimeter of the triangle is:" << endl;
cout << perimeter << endl;
cout << " " << endl;
}

else if ( menuChoice2 == 2 )
{
cout << "Please enter the perpendicular height of the rectangle:" << endl;
cin >> height;
cout << " " << endl;
cout << "Please enter the length of the triangles base:" << endl;
cin >> base;
cout << " " << endl;
base = base/2;
area = base*height;
cout << "The area is:" << endl;
cout << area << endl;
cout << " " << endl;
}
}
//RECTANGLE
void rectangle ()
{
double perimeter  = 0, area = 0, height  = 0, width = 0, menuChoice3 = 0;

cout << "Please choose an option:" << endl;
cout << "1. Perimeter" << endl;
cout << "2. Area" << endl;
cout << " " << endl;
cin >> menuChoice3;
cout << " " << endl;


if ( menuChoice3 == 1 )
{
cout << "Please enter the height of the rectangle:" << endl;
cin >> height;
cout << " " << endl;
cout << "Please enter the width of the rectangle:" << endl;
cin >> width;
cout << " " << endl;
perimeter = height + height + width + width;
cout << "The perimeter is:" << endl;
cout << perimeter << endl;
cout << " " << endl;
}
else if ( menuChoice3 == 2 )
{
cout << "Please enter the height of the rectangle:" << endl;
cin >> height;
cout << " " << endl;
cout << "Please enter the width of the rectangle:" << endl;
cin >> width;
cout << " " << endl;
area = height*width;
cout << "The area is:" << endl;
cout << area << endl;
cout << " " << endl;
}
}
}


p.s. Sorry about the bad indentation!
Last edited on
Can you post the error message that you are getting...
closed account (z05DSL3A)
Your functions should be defined outside of the main function.

Delete the } at line 170 and put one in at line 43.

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "stdafx.h"
#include <math.h>
#include <iostream>
#include <vector>
#include <conio.h>

using namespace std;

void circle ();
void triangle ();
void rectangle ();

int main()
{
    int menuChoice = 0;
    cout << "Do you require:-" << endl;
    cout << "1. Circle" << endl;
    cout << "2. Triangle" << endl;
    cout << "3. Rectangle" << endl;
    cout << "4. Quit" << endl;
    cout <<" " << endl;
    cin >> menuChoice;
    cout << " " << endl;


    if (menuChoice == 1)
    {
        circle ();
    }
    else if (menuChoice == 2)
    {
        triangle ();
    }
    else if (menuChoice == 3)
    {
        rectangle ();
    }
    else if (menuChoice == 4)
    {
        cout << "Goodbye" << endl << endl;
    }
}

// CIRCLE!!!
void cicrle ()
{
    double circumference = 0, area = 0, diameter = 0, radius = 0, pi = 0, menuChoice1 = 0;

    cout << "Please choose an option: " << endl;
    cout << "1. Circumference" << endl;
    cout << "2. Area" << endl;
    cout << " " << endl;
    cin >> menuChoice1;
    cout << " " << endl;


    if ( menuChoice1 == 1 )
    {
        cout << "Please enter the diameter of the circle: " << endl;
        cin >> diameter;
        cout << " " << endl;
        cout << "Please enter the value of Pi you wish to use: " << endl;
        cin >> pi;
        cout << " " << endl;
        circumference = diameter*pi;
        cout << "The circumference is: " << endl;
        cout << circumference << endl;
        cout << " " << endl;
    }
    else if ( menuChoice1 == 2 )
    {
        cout << "Please enter the radius (half the diameter) of the circle: " << endl;
        cin >> radius;
        cout << " " << endl;
        cout << "Please enter the value of Pi you wish to use: " << endl;
        cin >> pi;
        cout << " " << endl;
        radius = radius * radius;
        area = radius * pi;
        cout << "The area is: " << endl;
        cout << area << endl;
        cout << " " << endl;
    }
}
//TRIANGLE
void triangle ()
{
    double perimeter = 0, area = 0, sideA = 0, sideB = 0, sideC = 0, height = 0, base = 0, menuChoice2 = 0;

    cout << "Please choose an option: " << endl;
    cout << "1. Perimeter" << endl;
    cout << "2. Area" << endl;
    cout << " " << endl;
    cin >> menuChoice2;
    cout << " " << endl;

    if ( menuChoice2 == 1 )
    {
        cout << "Please enter the length of side A:" << endl;
        cin >> sideA;
        cout << " " << endl;
        cout << "Please enter the length of side B:" << endl;
        cin >> sideB;
        cout << " " << endl;
        cout << "Please enter the length of side C:" << endl;
        cin >> sideC;
        cout << " " << endl;
        perimeter = sideA + sideB + sideC;
        cout << "The perimeter of the triangle is:" << endl;
        cout << perimeter << endl;
        cout << " " << endl;
    }
    else if ( menuChoice2 == 2 )
    {
        cout << "Please enter the perpendicular height of the rectangle:" << endl;
        cin >> height;
        cout << " " << endl;
        cout << "Please enter the length of the triangles base:" << endl;
        cin >> base;
        cout << " " << endl;
        base = base/2;
        area = base*height;
        cout << "The area is:" << endl;
        cout << area << endl;
        cout << " " << endl;
    }
}
//RECTANGLE
void rectangle ()
{
    double perimeter  = 0, area = 0, height  = 0, width = 0, menuChoice3 = 0;

    cout << "Please choose an option:" << endl;
    cout << "1. Perimeter" << endl;
    cout << "2. Area" << endl;
    cout << " " << endl;
    cin >> menuChoice3;
    cout << " " << endl;


    if ( menuChoice3 == 1 )
    {
        cout << "Please enter the height of the rectangle:" << endl;
        cin >> height;
        cout << " " << endl;
        cout << "Please enter the width of the rectangle:" << endl;
        cin >> width;
        cout << " " << endl;
        perimeter = height + height + width + width;
        cout << "The perimeter is:" << endl;
        cout << perimeter << endl;
        cout << " " << endl;
    }
    else if ( menuChoice3 == 2 )
    {
        cout << "Please enter the height of the rectangle:" << endl;
        cin >> height;
        cout << " " << endl;
        cout << "Please enter the width of the rectangle:" << endl;
        cin >> width;
        cout << " " << endl;
        area = height*width;
        cout << "The area is:" << endl;
        cout << area << endl;
        cout << " " << endl;
    }
}
Last edited on
you have spend ages and you are writting the spelling of circle wrong!!!

void cicrle ()
Bloody hell, I didn't even realise that!
Hahah thanks alot!

Tom Yallop
Okay, so I fixed that spelling mistake, but I'm still getting the following errors:
1
2
3
4
5
6
1>c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(49) : error C2601: 'circle' : local function definitions are illegal
1>        c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(15): this line contains a '{' which has not yet been matched
1>c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(91) : error C2601: 'triangle' : local function definitions are illegal
1>        c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(15): this line contains a '{' which has not yet been matched
1>c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(135) : error C2601: 'rectangle' : local function definitions are illegal
1>        c:\users\tom\desktop\cw\exercise 2 this one\exercise 2 this one\exercise 2 this one.cpp(15): this line contains a '{' which has not yet been matched


Any suggestions??


Thanks
Tom Yallop
Grey Wolf, you are a live saver!
It works fine now.

Thanks a lot for all your help people, I'm very grateful!


Tom Yallop
but gcc doesnt give error if you define your functions in main. :)
Topic archived. No new replies allowed.