本方案的所期望的結果的語句和函數如下:問題與環路涉及如果是
選擇形狀(1)球(2)筒(3)錐形(q)中退出:1
選擇計算(1)體積(2)表面積:1
輸入球體的半徑:球體的5.5
體積是696.91
選擇形狀(1)球(2)筒(3)錐形(q)中退出:1
選擇計算(1)體積(2)表面積:2
輸入球體的半徑:球體的5.5
表面積是380.133
選擇形狀(1)球(2)筒(3)錐形(q)中退出:2
選擇一個計算(1)體積( 2)表面積:1
輸入氣缸的半徑:5.5
輸入氣缸的高度:4.2
捲筒的是399.139
選擇形狀(1)球(2)筒(3)錐形(q )quit:2
選擇一個計算(1)volume(2)surface ar EA:2
輸入氣缸的半徑:5.5
輸入氣缸的高度:氣缸的4.2
表面積是335.208
選擇形狀(1)球(2)筒(3)錐形(q)中退出:3
選擇一個計算(1)體積(2)表面積:1
輸入錐體的半徑:5.5
輸入錐體的高度:4.2
卷錐體的是133.046
選擇形狀(1 )球(2)圓柱體R(3)錐形(q)中退出:3
選擇一個計算(1)體積(2)表面積:2
輸入錐體的半徑:5.5
輸入錐體的高度:錐體的4.2
表面積是214.607
選擇形狀(1)球(2)筒(3)錐形(q)中退出:q
再見!
我想你可以告訴我在哪裏帶着這個......爲什麼我不能讓我的循環正常工作?
#include <iostream>
#include <math.h>
using namespace std;
double sphere_volume(double radius);
double sphere_surface_area(double radius);
double cylinder_volume(double radius, double height);
double cylinder_surface_area(double radius, double height);
double cone_volume(double radius, double height);
double cone_surface_area(double radius, double height);
int main()
{
double entHeight;
double entRadius;
char shapeCall;
char compCall;
cout << "Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: ";
cin >> shapeCall;
cout << "Select a Computation (1) volume (2) surface area: ";
cin >> compCall;
if (shapeCall == 1 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_volume (entRadius) << endl;
}
if (shapeCall == 1 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << sphere_surface_area (entRadius) << endl;
}
if (shapeCall == 2 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_volume (entRadius, entHeight) << endl;
}
if (shapeCall == 2 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cylinder_surface_area (entRadius, entHeight) << endl;
}
if (shapeCall == 3 && compCall == 1)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_volume (entRadius, entHeight) << endl;
}
if (shapeCall == 3 && compCall == 2)
{
cout << "Enter Radius: ";
cin >> entRadius;
cout << "Enter Height: ";
cin >> entHeight;
cout << cone_surface_area (entRadius, entHeight) << endl;
}
system ("pause");
return 0;
}
double sphere_Volume(double radius)
{
return 4.0/3.0 * 3.14159 * pow(radius, 3);
}
double cylinder_volume(double radius, double height)
{
return 3.14159 * pow(radius, 2) * height;
}
double cone_volume(double radius, double height)
{
return 1.0/3.0 * 3.14159 * pow(radius, 2) * height;
}
double sphere_surface_area(double radius)
{
return 4.0 * 3.14159 * pow(radius, 2);
}
double cylinder_surface_area(double radius, double height)
{
return (2.0 * 3.14159 * pow(radius, 2)) + (2.0 * 3.14159 * radius * height);
}
double cone_surface_area(double radius, double height)
{
return (3.14159 * pow(radius, 2)) + (3.14159 * radius * sqrt(pow(radius, 2) + pow(height, 2)));
}
以什麼方式不能正常工作?你到目前爲止做了哪些調試? – 2013-02-23 11:39:05
請不要發表兩次相同的問題。 – 2013-02-23 11:40:53