Need help with cylinder surface area (for school)

Feb 13, 2017 at 6:03am
Struggling getting the volume and surface area of a cynlinder for a school assignment. Anyone think they can help 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
  /***************************
*     libraries
****************************/
#include <iostream>            // needed for Cin and Cout
#include <cmath>

using namespace std;

/************************************
*     defines
*************************************/
#define  PI  3.14159

/*************************************
*     function prototype
*************************************/

int main()
{
	float radius, height, surface, volume;
	int pi = 3.14159

		//Get radius 
	cout << "enter the radius: ";
	cin >> radius;

	//Get height
	cout << "enter the height: ";
	cin >> height;

	//Get the volume area
	volume = pi*(float)radius^2 * height;
	cout << "The volume area is: " << volume << endl;

	//Get the surface area
	surface = 2 * pi *(float)radius ^ 2 + 2 * pi * radius * height;
	cout << "The surface area is: " << surface << endl;

	
	system("pause");
	return 0;
}
Feb 13, 2017 at 6:09am
Line 32 and line 36 are wrong. The ^ is NOT a power function. Just replace it with *radius here. You don't need (float) in that line either.

Also, pi is not an integer! Make it a float ( better still, a double).
Feb 13, 2017 at 6:14am
now mine has an error on line 24 for some reason this is what i have now

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
/***************************
*     libraries
****************************/
#include <iostream>            // needed for Cin and Cout
#include <cmath>

using namespace std;

/************************************
*     defines
*************************************/
#define  PI  3.14159

/*************************************
*     function prototype
*************************************/

int main()
{
	float radius, height, surface, volume;
	float pi = 3.14159

	//Get radius 
	cout << "enter the radius: ";
	cin >> radius;

	//Get height
	cout << "enter the height: ";
	cin >> height;

	//Get the volume area
	volume = pi*(float)radius * 2 * height;
	cout << "The volume area is: " << volume << endl;

	//Get the surface area
	surface = 2 * pi *(float)radius * 2 + 2 * pi * radius * height;
	cout << "The surface area is: " << surface << endl;


	system("pause");
	return 0;
}
Last edited on Feb 13, 2017 at 6:16am
Feb 13, 2017 at 6:40am
You're missing a semi-colon on line 21.
Also, remove the unnecessary casts. You don't need them.
Feb 13, 2017 at 7:13am
Now your formulae for volume and surface area are simply wrong. If you want "radius squared" then simply write radius * radius, not radius * 2, on lines 32 and 36.
Topic archived. No new replies allowed.