Thread: Volume of a cylinder: volume_cylinder = PI * radius2 * height

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    12

    Volume of a cylinder: volume_cylinder = PI * radius2 * height

    Code:
    /*Name:Brian
    Date:9/3/17
    First Project
    
    
    */
    
    
    
    
    #include <stdio.h>
    
    
    int main(void) {
        double mass=0.00, acceleeration=0.00 , force=0.00,radius=0.0, height=0.0, volume=0.0, pi=3.14 ;
    
    
        //1. Promot the user for the mass and acceleration
        printf("Please enter the mass and accleeration <both floating-points values> for use in Newton's Second Law ");
    
    
        //2. Get the mass and accleration from the user
        scanf("%lf %lf", &mass, &acceleeration);
    
    
        //printf("%d %d\n", mass, acceleeration);
    
    
    
    
        //3. Mutliply the mass with accelleration
        force = mass * acceleeration;
    
    
        //4. Put it together
        printf("Newton's Second Law: force = mass*acceleeration= %lf\n",force);
    
    
    
    
        
        
        
        
        //2.1 Promot the user for the radius and height
        printf("Please enter the radius and the height <both floating-point values> for use in a volume of a cylinder equation ");
    
    
        //2.2 Get the radius and height from the user
        scanf("%lf %lf", &radius, &height);
    
    
        //2.3 Get the value of the volume
        volume = (1 / 3)*radius*pi*height*radius;
        
        
        //2.4 Put it together
        printf("Volume of a cylinder: volume_cylinder = PI* radius^2*height= %lf\n", volume);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }

    Whenever i run the volume part of my code, i get 0.000 as my answer. I'm not sure what i did wrong. Any help is welcome, thanks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Try dividing decimals instead of integers to get an answer. In C, there is a difference: 1 / 3 in integer division is 0.

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    12

    Thanks

    Quote Originally Posted by whiteflags View Post
    Try dividing decimals instead of integers to get an answer. In C, there is a difference: 1 / 3 in integer division is 0.
    Yea it worked, but the volume of a cylinder does not include .333333. But if it did, inputing .3333333 instead of (1/3) works, so thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Area and volume of cylinder
    By melissax in forum C++ Programming
    Replies: 9
    Last Post: 04-28-2013, 07:21 AM
  2. USB Problem : Volume to Volume copy by sector
    By anuj7anuj in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2011, 08:47 AM
  3. OpenGL: Draw cylinder yourself
    By iMPR3SSiON in forum Game Programming
    Replies: 5
    Last Post: 01-11-2011, 09:55 PM
  4. Raw volume access (to a usb volume)
    By _izua_ in forum Windows Programming
    Replies: 9
    Last Post: 11-02-2009, 07:05 AM
  5. Cone/Cylinder source
    By Fab in forum C Programming
    Replies: 5
    Last Post: 11-22-2005, 03:50 PM

Tags for this Thread