C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-31-2009, 07:52 PM   #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?
Neotriz is offline   Reply With Quote
Old 10-31-2009, 08:00 PM   #2
a_capitalist_story
 
Join Date: Dec 2007
Posts: 1,061
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 *’
rags_to_riches is offline   Reply With Quote
Old 10-31-2009, 08:07 PM   #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?
Neotriz is offline   Reply With Quote
Old 10-31-2009, 08:15 PM   #4
a_capitalist_story
 
Join Date: Dec 2007
Posts: 1,061
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.
rags_to_riches is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with basic calculation program. StateofMind C Programming 18 03-06-2009 01:44 AM
Help with day of the week program Punkakitty C++ Programming 10 01-14-2009 06:55 PM
I'm so close to finishing this...please help with logic error crazychile C Programming 8 11-03-2008 09:48 PM
The Timing is incorret Drew C++ Programming 5 08-28-2003 04:57 PM
Another Calendar/Birthday Question-Please help- SORRY! dauz C Programming 4 04-22-2003 12:52 PM


All times are GMT -6. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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