#include
#include
using namespace std;
void calccuboid();
void calccylinder();
void calccone();
int main()
{
int choice = -1;
while (choice)
{
cout <<"1.长方体"< cout cout cin >> choice;
switch (choice)
{
case 1:
calccuboid();
break;
case 2:
calccylinder();
break;
case 3:
calccone();
break;
}
}
cout <<"感谢使用本软件!" < }
void calccuboid()
{
double len,width,height;
cout cin >>len>>width>>height;
double v = len*width*height;
cout <<"长方体的体积为:"< }
void calccylinder()
{
double radius,height;
cout cin >>radius>>height;
double v = 3.14*pow(radius,2)*height;
cout <<"圆柱体的体积为:"< }
void calccone()
{
double radius,height;
cout cin >>radius>>height;
double v = 3.14/3*pow(radius,2)*height;
cout <<"圆锥体的体积为:"<<v<<endl;
}
为什么输入0,就会出现cout的感谢使用本软件!语句而输入4,5之类的只会继续循环 。
因为你的循环while (choice),当choice是0的时候,循环就不能继续,退出前打印“感谢使用本软件!”
而4、5只是case不执行语句,但是会继续循环