Thread: Finding the total mass of a snowman

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

    Question Finding the total mass of a snowman

    With using functions, I'm supposed to find the total mass of a snowman.

    For some reason, it's giving me the wrong answer:

    Code:
    #include <stdio.h>
    
    #define PI 3.14159
    #define SNOW_DEN 0.1
    
    double Sphere_Volume( double radius);
    double Sphere_Mass (double den, double volume);
    
    int main() {
        int radius_1, radius_2, radius_3;
        double total_volume;
        double total_mass;
    
    
        printf("What is the radii of the head, body and leg of the snowman?\n");
        scanf("%lf%lf%lf", &radius_1, &radius_2, &radius_3);
        
        total_volume= Sphere_Volume(radius_1)+ Sphere_Volume(radius_2) + Sphere_Volume(radius_3);
        total_mass= Sphere_Mass(SNOW_DEN, total_volume);
        
        printf("The total Mass in grams is %lf.\n", total_mass);
        
        system("PAUSE");
        return 0;
    }
    
    
    double Sphere_Volume( double radius){
           return 4*PI/3*radius*radius*radius;
    }
           
    double Sphere_Mass (double den, double volume){
           return  SNOW_DEN*volume;
    }

    Where am I doing wrong?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Turning up your warnings may have helped:
    Code:
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 2 has type ‘int *’
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 3 has type ‘int *’
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 4 has type ‘int *’

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    32
    Quote Originally Posted by rags_to_riches View Post
    Turning up your warnings may have helped:
    Code:
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 2 has type ‘int *’
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 3 has type ‘int *’
    snowman.c:16: warning: format ‘%lf’ expects type ‘double *’, but argument 4 has type ‘int *’
    Thanks for the tip mate.

    How do you turn up the warnings?

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Depends on the compiler. I used gcc, so I used
    Code:
    gcc -Wall -pedantic -std=c99 -o snowman snowman.c
    I also got
    Code:
    snowman.c:23: warning: implicit declaration of function ‘system’
    because you didn't include stdlib.h, where system() is declared.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  2. Help with day of the week program
    By Punkakitty in forum C++ Programming
    Replies: 10
    Last Post: 01-14-2009, 06:55 PM
  3. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. Replies: 4
    Last Post: 04-22-2003, 12:52 PM