C++编程求长方体体积
来源:百度知道 编辑:UC知道 时间:2024/06/26 04:17:06
菜鸟刚刚学习C++,遇到以下问题,请高手帮忙解决一下哈
要求:从键盘输入长方体的长,宽,高(都为double型)的值,然后求体积(整型)
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
double length, width, height,;
cout<<"Give the length,width and height of a rectangular block"<<endl;
cin>>length,width,height;
int volume=length*width*height;
cout<<"The volume of the block is: "<< volume <<endl;
system("PAUSE");
return 0;
}
为什么我输入20.0 10.0 2.0以后,体积显示为0呢?!(要求结果显示为400)哪位高手能指点一下呢?
要求:从键盘输入长方体的长,宽,高(都为double型)的值,然后求体积(整型)
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
double length, width, height,;
cout<<"Give the length,width and height of a rectangular block"<<endl;
cin>>length,width,height;
int volume=length*width*height;
cout<<"The volume of the block is: "<< volume <<endl;
system("PAUSE");
return 0;
}
为什么我输入20.0 10.0 2.0以后,体积显示为0呢?!(要求结果显示为400)哪位高手能指点一下呢?
cin>>length,width,height;这里的逗号改成是提取运算符就行了,如果是逗号的话,输入的值不能赋给width和height。
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
double length, width, height;
cout<<"Give the length,width and height of a rectangular block"<<endl;
cin>>length>>width>>height;
int volume=length*width*height;
cout<<"The volume of the block is: "<< volume <<endl;
system("PAUSE");
return 0;
}
cin>>length,width,height; 分开输入吧,不要这样写,应该向下面这样写。
cin>>length;
cin>>width;
cin>>height;
或者cin>>length>>width>>height;
cin>>length>>width>>hight;
没有说中间带逗号的