# Thread: Helpp Do Not Know Where To Start

1. ## Helpp Do Not Know Where To Start

Write an interactive C or C++ program to calculate the surface area of a cylinder. In the header comment of your code, write the pseudocode for the program. Include a screenshot showing that's you have tested your program.

2. cylinder surface area calculates with formula: 2*pi*R*h + 2*pi*R^2, so the input should be h and R values of cylinder. The program code:

float area, R, h;

area = 2*3.14*R*h + 2*3.14*R*R;

that's all

3. o thats it? thats all that i put in my complier?

4. Of course, you need to write the other parts of the program to actually get it to compile and run. You also need to write the part that reads in input and prints the output.

5. Begin with the pseudo-code which apparently you have to write anyway.

The formula for this only involves two variable, radius and height. You don't need <math.h>, but you do need pi, which you can just define this way:
Code:
`#define PI 3.1415`
I would say the pseudo-code involves slightly more than just the formula, btw

6. #include<stdio.h>
#include<math.h>

/*prompt the user for the radius
prompt the user for the height
get the height
compute the surface area of the cylinder
display the value of radius, height and the calculated surface area
*/

int main ()
{

int r;
int h;
double sa;
printf("Enter a value for the radius:");
scanf("%d",&r);

printf("Enter a value for the height:");
scanf("%d",&h);

sa= 2 * M_PI * (r * r) + 2 * M_PI * r * h;

printf( "height is %d\n", h);
printf( "surface area is %f\n", sa);

return (0);

is this right?

7. I doubt if most cylinders would have a radius or a height, that would be an even integer. Better make them double.

Either put a space before the % in your second scanf() line, or add a getchar() statement, after the first scanf() call, to pull the newline that scanf() will always leave behind, off the keyboard buffer.

Second scanf() should be skipped unless you do.

Also, use code tags on our forum, please. Just highlight the program code, and click on the "#" mark on the advanced reply window.

Also, I'd add a getchar() or scanf() or something, on the line before the return, to hold the console window open long enough to get your screenshot, unless you redirect it, anyway.