Helpp Do Not Know Where To Start

This is a discussion on Helpp Do Not Know Where To Start within the C Programming forums, part of the General Programming Boards category; Write an interactive C or C++ program to calculate the surface area of a cylinder. In the header comment of ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    32

    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. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    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. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    32
    o thats it? thats all that i put in my complier?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,960
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    32
    #include<stdio.h>
    #include<math.h>

    /*prompt the user for the radius
    get 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( "radius is %d\n", r);
    printf( "height is %d\n", h);
    printf( "surface area is %f\n", sa);



    return (0);


    is this right?

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.
    Last edited by Adak; 03-12-2009 at 08:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. C++ gui for windows where to start
    By prixone in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2006, 10:48 PM
  4. GNOME Desktop won't start (Mandriva)
    By psychopath in forum Tech Board
    Replies: 10
    Last Post: 07-19-2006, 01:21 PM
  5. Where do I start?
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 04-08-2002, 12:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21