Volume of a Snowman scanf() help!

Hey, I am new here and was wondering if someone more knowledgeable could give me a couple pointers... I think the problem has to do with the scanf() function and improper coding, but I cannot figure out what I am doing wrong.

The requirements are:
Calculate the volume of snow, in cubic feet, that it would take to build a snowman, made of 3 round snowballs.

Read the diameter of the top, middle, and bottom snowballs from the user in inches. Calculate the volume of each required snowball and the total volume and print all 4 values, with appropriate labels and exactly 1 decimal place. Use a constant to hold the number of inches in 1 foot.

/* Snowman program */

#include <stdio.h>
#include <math.h>
#define PI 3.141593

int main(void)
{
double x, y, z; //x= bottom diameter, y= middle diameter, z= top diameter
double Vol_Bot;
double Vol_Mid;
double Vol_Top;
double Vol_Tot;

/*Asks for the bottom, middle, and top diameters*/
printf("Enter the value for the bottom, middle, and top diameters>");
scanf("%lf", &x);
scanf("%lf", &y);
scanf("%lf", &z);

Vol_Bot = (4.0/3.0) * PI * (x/2.0) * (x/2.0) * (x/2.0);
Vol_Mid = (4.0/3.0) * PI * (y/2.0) * (y/2.0) * (y/2.0);
Vol_Top = (4.0/3.0) * PI * (z/2.0) * (z/2.0) * (z/2.0);

printf("The bottom volume is> %lf", &Vol_Bot);

printf("The middle volume is> %lf", &Vol_Mid);

printf("The top volume is> %lf", &Vol_Top);

Vol_Tot = Vol_Bot + Vol_Mid + Vol_Top;
printf("The total volume is> %lf", &Vol_Tot);

return(0);


}

When the program compiles no errors appear. When the program runs all inputs add up to incorrect values.
What IDE are you using? It should give you load of warnings.
1) Send to printf actual variables, not the pointer to them (get rid of "&" before function argument)
2) Gcc gives me a warning on "%lf" in printf and working incorrectly. if you will have problems with that, change it to "%f".
Last edited on
The problem is in your printf statements. You're passing the address of Vol_Bot, Vol_Mid and Vol_Top. You should be passing the values, not the addresses.
1
2
3
printf("The bottom volume is> %lf", Vol_Bot);
printf("The middle volume is> %lf", Vol_Mid);
printf("The top volume is> %lf", Vol_Top);


PLEASE USE CODE TAGS (the <> formatting button) when posting code.


Thanks, I didn't expect so quick of a reply. I am using Code::Blocks with build 12.11.

Removing the '&' in the printf() functions did the trick. I also tried removing the'l' from "%lf", but no luck. thanks to both of you!
Topic archived. No new replies allowed.