Error driving me nuts... any help is greatly appriciated

This error keeps laughing at me

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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
******************************************************************
CSCI 240         Program 5 Part 2     Spring 2013

Programmer: 
Section: 1

Date Due: 3/1/13

Purpose:   This program uses functions to calculate the surface
           area of various shapes.

           It is an exercise in learning to write functions.
******************************************************************/

#include <iostream>
#include <iomanip>

using namespace std;

#define PI 3.14
//Symbolic constant for the value of PI


int Menu();
int getValue( string prompt, int lowerBound, int upperBound );
float calcSphere( int radius );
float calcPrism( int length, int width, int height );
float calcCone( int radius, int length );
float calcPyramid( int length, int slantHeight );


//Function Prototypes, not sure if right







int main()
{
int menuChoice,     //The users choice from the menu
    radius,         //The radius for the sphere and cone
    length,         //The length of the side of the cone, prism, and pyramid
    height,         //The height of the side of the prism and pyramid
    width;          //The width of the side of the prism

float surfArea;     //The surface area of all of the shapes


//Print the surface areas with 4 digits after the decimal points

cout << fixed << showpoint << setprecision(4);


//Display the menu to the user and get their choice

menuChoice = Menu();


//While the user does not want to quit

while( menuChoice != 5 )
  {

  //If the user wants to calculate the surface area of a sphere, get the
  //radius of the sphere and then display the calculated surface area

  if( menuChoice == 1 )
    {
    radius = getValue( "Enter the radius for the sphere", 1, 10 );

    surfArea = calcSphere( radius );

    cout << endl << "The surface area of a sphere with radius " << radius
         << " is " << surfArea;    
    }


  //If the user wants to calculate the surface area of a cone, get the
  //radius of the base and the length of the side of the cone, and then
  //display the calculated surface area

  else if ( menuChoice == 2 )
    {
    radius = getValue( "Enter the radius of the base of the cone", 1, 7 );

    length = getValue( "Enter the length of the side of the cone", 1, 12 );

    surfArea = calcCone( radius, length );

    cout << endl << "The surface area of a cone with radius " << radius
         << " and side length " << length << " is " << surfArea;    
    }


  //If the user wants to calculate the surface area of a prism, get the
  //length, width, and height of the side of the prism, and then display
  //the calculated surface area

  else if ( menuChoice == 3 )
    {
    length = getValue( "Enter the length of the side of the prism", 1, 20 );
    width = getValue( "Enter the width of the side of the prism", 1, 20 );
    height = getValue( "Enter the height of the side of the prism", 1, 20 );

    surfArea = calcPrism( length, width, height );

    cout << endl << "The surface area of the prism with length " << length
         << " width " << width << " and height " << height << " is " << surfArea;    
    }


  //Otherwise, the user wants to calculate the surface area of a pyramid.
  //Get the length of the base and the slant height of the pyramid, and
  //then display the calculated surface area

  else 
    {
    length = getValue( "Enter the length of the base of the pyramid", 1, 10 );
    height = getValue( "Enter the slant height of the pyramid", 1, 15 );

    surfArea = calcPyramid( length, height );

    cout << endl << "The surface area of the pyramid with base " << length
         << " and slant height " << height << " is " << surfArea;    
    }


  //Get another menu choice from the user

  menuChoice = Menu();
  }

return 0;
}



//********** Code the functions below this line **********
int Menu()
{
int menuChoice;

cout << "\n\n\nSurface Area Calulator\n\n";
cout << "1 Sphere\n";
cout << "2 Cone\n";
cout << "3 Rectangular Prism\n";
cout << "4 Pyramid\n";
cout << "5 Quit\n\n";
cout << "Enter your choice (1-5): ";
cin >> menuChoice;

while( menuChoice < 1 or menuChoice > 5 )
  {
  cout << "WRONG ANSWER! Try again: ";
  cin >> menuChoice;
  }

return menuChoice;


}

/***************************************************************
menu
Function: displays menu and gets choice

Use: check for validity and give user another chance if an invalid option is chosen

Arguments: takes no arguments

Returns: retuned to main()

Notes: sphere, pyramid, cone, rectangular prism, exit
***************************************************************/

int getValue( string prompt, int lowerBound, int upperBound );

{
int userNum;

cout << "Enter a number between" << lowerBound << "and " << upperBound << ": ";
cin >> userNum;

while( userNum < 0 or userNum > upperBound )
  {
  cout << "You messed again! Try again: ";
  cin >> userNum;
  }

return userNum;


}
/***************************************************************
Bounds
Function: get an integer value from user in a certain range 

Use: makes sure value is in certain range

Arguments: a string and two integers

Returns: calling function

Notes:value = getValue( "Enter the radius for the sphere", 1, 10 );
***************************************************************/
float calcSphere( int radius );
{
	
return 4 * PI * (radius*radius)
}
/***************************************************************
sphere
Function: calculate surface area of a sphere

Use: does math based on formula

Arguments:  an integer that holds the radius of the sphere

Returns:  a floating point value which is the calculated surface area

Notes: Surface Area of Sphere = 4 * pi * radius2
***************************************************************/

float calcPrism( int length, int width, int height );
{
return ( 2 * length * width ) + ( 2 * width * height ) +
                                    ( 2 * length * height )
}
/***************************************************************
prism
Function: calculate surface area of a prism

Use:does math based on formula

Arguments: an integer that holds the length of the side of the prism, an integer that holds the width of the side of the prism, an integer that holds the height of the side of the prism

Returns: returns a floating point value which is the calculated surface area

Notes:Surface Area of Rectangular Prism = ( 2 * length * width ) + ( 2 * width * height ) +
                                    ( 2 * length * height )
***************************************************************/

float calcCone( int radius, int length );
{
return ( PI * radius * length ) + ( PI * (radius*radius) )
	
}
/***************************************************************
cone
Function: calculate surface area of a cone

Use: does math based on formula

Arguments: an integer that holds the radius of the base of the cone, and an integer that holds the length of the side of the cone 

Returns: a floating point value which is the calculated surface area.

Notes: Surface Area of Cone = ( pi * radius * length ) + ( pi * radius2 )
***************************************************************/

float calcPyramid( int length, int slantHeight );
{
return ( 2 * length * height ) + (length*length)
	
}
/***************************************************************
pyramid
Function: calculate surface area of a pyramid 

Use: does math based on formula

Arguments: an integer that holds the length of the base of the pyramid, and an integer that holds the slant height of the pyramid

Returns: floating point value which is the calculated surface area.

Notes: Surface Area of Pyramid = ( 2 * length * height ) + length2
***************************************************************/
Last edited on
Put the code between [code] and [/code]

Could you copy and paste the actual error?
error expected unqualified-id before '{ ' token

on line 181 sorry, dont know y it changed
Last edited on
You have your semicolon in the wrong place:
1
2
3
4
5
float calcSphere( int radius ) //you had it here
{

    return 4 * PI * (radius*radius); //but it belongs here
}


You did that for a few functions.

Also, in your calcPyramid function, you have try to use height, but the argument's name is slantHeight:
1
2
3
4
5
float calcPyramid( int length, int slantHeight ); //int slantHeight and misplaced ;
{
    return ( 2 * length * height ) + (length*length) //height not defined
	
}


After fixing those errors, I got it to run.
You have an extra semicolon at the end of line 179
still get same error at 181 :(
Please repost your latest 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/******************************************************************
CSCI 240         Program 5 Part 2     Spring 2013

Programmer: 

Section: 1

Date Due: 3/1/13

Purpose:   This program uses functions to calculate the surface
           area of various shapes.

           It is an exercise in learning to write functions.
******************************************************************/

#include <iostream>
#include <iomanip>

using namespace std;

#define PI 3.14
//Symbolic constant for the value of PI


int Menu();
int getValue( string prompt, int lowerBound, int upperBound );
float calcSphere( int radius );
float calcPrism( int length, int width, int height );
float calcCone( int radius, int length );
float calcPyramid( int length, int slantHeight );


//Function Prototypes, not sure if right







int main()
{
int menuChoice,     //The users choice from the menu
    radius,         //The radius for the sphere and cone
    length,         //The length of the side of the cone, prism, and pyramid
    height,         //The height of the side of the prism and pyramid
    width;          //The width of the side of the prism

float surfArea;     //The surface area of all of the shapes


//Print the surface areas with 4 digits after the decimal points

cout << fixed << showpoint << setprecision(4);


//Display the menu to the user and get their choice

menuChoice = Menu();


//While the user does not want to quit

while( menuChoice != 5 )
  {

  //If the user wants to calculate the surface area of a sphere, get the
  //radius of the sphere and then display the calculated surface area

  if( menuChoice == 1 )
    {
    radius = getValue( "Enter the radius for the sphere", 1, 10 );

    surfArea = calcSphere( radius );

    cout << endl << "The surface area of a sphere with radius " << radius
         << " is " << surfArea;    
    }


  //If the user wants to calculate the surface area of a cone, get the
  //radius of the base and the length of the side of the cone, and then
  //display the calculated surface area

  else if ( menuChoice == 2 )
    {
    radius = getValue( "Enter the radius of the base of the cone", 1, 7 );

    length = getValue( "Enter the length of the side of the cone", 1, 12 );

    surfArea = calcCone( radius, length );

    cout << endl << "The surface area of a cone with radius " << radius
         << " and side length " << length << " is " << surfArea;    
    }


  //If the user wants to calculate the surface area of a prism, get the
  //length, width, and height of the side of the prism, and then display
  //the calculated surface area

  else if ( menuChoice == 3 )
    {
    length = getValue( "Enter the length of the side of the prism", 1, 20 );
    width = getValue( "Enter the width of the side of the prism", 1, 20 );
    height = getValue( "Enter the height of the side of the prism", 1, 20 );

    surfArea = calcPrism( length, width, height );

    cout << endl << "The surface area of the prism with length " << length
         << " width " << width << " and height " << height << " is " << surfArea;    
    }


  //Otherwise, the user wants to calculate the surface area of a pyramid.
  //Get the length of the base and the slant height of the pyramid, and
  //then display the calculated surface area

  else 
    {
    length = getValue( "Enter the length of the base of the pyramid", 1, 10 );
    height = getValue( "Enter the slant height of the pyramid", 1, 15 );

    surfArea = calcPyramid( length, height );

    cout << endl << "The surface area of the pyramid with base " << length
         << " and slant height " << height << " is " << surfArea;    
    }


  //Get another menu choice from the user

  menuChoice = Menu();
  }

return 0;
}



//********** Code the functions below this line **********
int Menu()
{
int menuChoice;

cout << "\n\n\nSurface Area Calulator\n\n";
cout << "1 Sphere\n";
cout << "2 Cone\n";
cout << "3 Rectangular Prism\n";
cout << "4 Pyramid\n";
cout << "5 Quit\n\n";
cout << "Enter your choice (1-5): ";
cin >> menuChoice;

while( menuChoice < 1 or menuChoice > 5 )
  {
  cout << "WRONG ANSWER! Try again: ";
  cin >> menuChoice;
  }

return menuChoice;


}

/***************************************************************
menu
Function: displays menu and gets choice

Use: check for validity and give user another chance if an invalid option is chosen

Arguments: takes no arguments

Returns: retuned to main()

Notes: sphere, pyramid, cone, rectangular prism, exit
***************************************************************/

int getValue( string prompt, int lowerBound, int upperBound )

{
int userNum;

cout << "Enter a number between" << lowerBound << "and " << upperBound << ": ";
cin >> userNum;

while( userNum < 0 or userNum > upperBound )
  {
  cout << "You messed again! Try again: ";
  cin >> userNum;
  }

return userNum;


}
/***************************************************************
Bounds
Function: get an integer value from user in a certain range 

Use: makes sure value is in certain range

Arguments: a string and two integers

Returns: calling function

Notes:value = getValue( "Enter the radius for the sphere", 1, 10 );
***************************************************************/
float calcSphere( int radius )
{
	
return 4 * PI * (radius*radius);
}
/***************************************************************
sphere
Function: calculate surface area of a sphere

Use: does math based on formula

Arguments:  an integer that holds the radius of the sphere

Returns:  a floating point value which is the calculated surface area

Notes: Surface Area of Sphere = 4 * pi * radius2
***************************************************************/

float calcPrism( int length, int width, int height )
{
return ( 2 * length * width ) + ( 2 * width * height ) +
                                    ( 2 * length * height )
}
/***************************************************************
prism
Function: calculate surface area of a prism

Use:does math based on formula

Arguments: an integer that holds the length of the side of the prism, an integer that holds the width of the side of the prism, an integer that holds the height of the side of the prism

Returns: returns a floating point value which is the calculated surface area

Notes:Surface Area of Rectangular Prism = ( 2 * length * width ) + ( 2 * width * height ) +
                                    ( 2 * length * height )
***************************************************************/

float calcCone( int radius, int length );
{
return ( PI * radius * length ) + ( PI * (radius*radius) )
	
}
/***************************************************************
cone
Function: calculate surface area of a cone

Use: does math based on formula

Arguments: an integer that holds the radius of the base of the cone, and an integer that holds the length of the side of the cone 

Returns: a floating point value which is the calculated surface area.

Notes: Surface Area of Cone = ( pi * radius * length ) + ( pi * radius2 )
***************************************************************/

float calcPyramid( int length, int Height );
{
return ( 2 * length * height ) + (length*length)
	
}
/***************************************************************
pyramid
Function: calculate surface area of a pyramid 

Use: does math based on formula

Arguments: an integer that holds the length of the base of the pyramid, and an integer that holds the slant height of the pyramid

Returns: floating point value which is the calculated surface area.

Notes: Surface Area of Pyramid = ( 2 * length * height ) + length2
***************************************************************/



now somethings up with lines 231,247,265. Thanks again guys
Last edited on
Missing a semicolon on 230
Extra semicolon on 246
Extra semicolon on 264

Seriously, you should be able to figure this out yourself by now ;)
I hope this helps

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
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

#define PI 3.14159265359
#define number 1.333333333333333333333333333333333
#define number2 .333333333333333333333333333333333
using namespace std;

void calcSphere(double radius)
{
    double volume = number * PI * radius * radius * radius;
    double surface = 4 * PI * radius * radius;

    cout << "The volume of the sphere is: " << volume << endl;
    cout << "The surface area of the sphere is: " << surface << endl;
    system("PAUSE");
}

void calcPrism(double length,double width,double height)
{
    double hypotenuse = sqrt((length * length) + (width * width));
    double perimeter = hypotenuse + length + width;
    double area = .5 * length * width;
    double area2 = area * height;
    double surface = 2 * area + perimeter * height;

    cout << "The perimeter of the base is: " << perimeter << endl;
    cout << "The area of the base is: " << area << endl;
    cout << "The area of the prism is: " << area2 << endl;
    cout << "The surface area of the prism is: " << surface << endl;
    system("PAUSE");
}

void calcCone(double height,double radius)
{
    double volume = number2 * PI * radius * radius * height;
    double surface = PI * radius * radius + PI * radius * sqrt((radius * radius) + (height * height));

    cout << "The volume of the cone is: " << volume << endl;
    cout << "The surface area of the cone is: " << surface << endl;
    system("PAUSE");
}

void calcPyramid(double base,double height)
{
    double apothem = .5 * base;
    double slant = sqrt((apothem * apothem) + (height * height));
    double volume = base * base * height;
    double surface = base * base + 4 * .5 * base * slant;

    cout << "The volume of the pyramid is: " << volume << endl;
    cout << "The surface area of the pyramid is: " << surface << endl;
    system("PAUSE");
}

int main(int nNumberofArgs,char* pszArgs[])
{
    int choice;
    double radius,length,width,height,base;

    cout << "Welcome to the area and surface area calculator!" << endl;

    for(;;)
    {
        cout << "1 - Sphere" << endl;
        cout << "2 - Prism" << endl;
        cout << "3 - Cone" << endl;
        cout << "4 - Pyramid" << endl;
        cout << "5 - Quit" << endl;
        cout << "Enter a number: ";
        cin >> choice;

        if(choice > 5 || choice < 1)
        {
            cout << "Please enter 1 to 5" << endl;
            system("PAUSE");
            return 0;
        }
        switch(choice)
        {
        case 1:
            cout << "Enter radius: ";
            cin >> radius;

            calcSphere(radius);
            system("CLS");
            break;
        case 2:
            cout << "Enter width of base leg, length of base leg, and height" << endl;
            cout << "Width: ";
            cin >> width;
            cout << endl;
            cout << "Length: ";
            cin >> length;
            cout << endl;
            cout << "Height: ";
            cin >> height;
            cout << endl;

            calcPrism(width,length,height);
            system("CLS");
            break;
        case 3:
            cout << "Enter height and radius" << endl;
            cout << "Height: ";
            cin >> height;
            cout << endl;
            cout << "Radius: ";
            cin >> radius;
            cout << endl;

            calcCone(height,radius);
            system("CLS");
            break;
        case 4:
            cout << "Enter length of a leg on base and height" << endl;
            cout << "Length: ";
            cin >> base;
            cout << endl;
            cout << "Height: ";
            cin >> height;
            cout << endl;

            calcPyramid(base,height);
            system("CLS");
            break;
        case 5:
            system("PAUSE");
            return 0;
        }
    }

}
lol yeah. that was embarrassing. You guys were very helpful!! +99999 karma to you both!
Topic archived. No new replies allowed.