我創建了這個程序,應該基本上使用公式V = Pi * h^2(3r-h)/ 3,但是我的最終答案沒有加起來。最終答案球體積的容量無效
例如:如果我用1代替半徑和2代表高度,我應該得到4.18,但是通過程序我得到-1。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double calculatevolume(double);
double main() {
double radius, height;
double sum; //for storing the radius of the reservoir given by the user
//for storing the calculated volume of the water.
printf("Please enter the Radius in meters first and then the Height in meters right after:\n"); //Displays the message on the screen
scanf("%lf",&radius);
printf("Value of r: %f\n", radius);
scanf("%lf",&height);
printf("Value of h: %f\n", height);
sum = calculatevolume(sum);
printf("For a reservoir of radius: %.2f m\nAnd a water depth: %.2f m\nThe water volume is: %.2f m^3\n",radius,height,sum);
system("PAUSE");
}
double calculatevolume(double sum) {
double radius;
double height;
sum = ((((3 * radius) - height)/3) * 3.14 * height * height);
return sum;
}
「ISN」加起來「不是一個有意義的問題描述。 –
什麼不加起來,你的主要回報是什麼? – doctorlove
檢查你的功能。半徑和高度並且爲空 - 將它們添加到參數 –