当我输入整数的时候运行没有问题,但输入浮点数的时候就有奇奇怪怪的问题,请问这个应该改怎么改呢
#include<iostream>
#include<cmath>
using namespace std;
class Circle
{
public:
int R;
float S;
//输入半径R
void setR()
{
cout<<"Please enter the radius of the circle:";
cin>>R;
}
//求底面圆面积
};
class Cylinder:public Circle
{
public:
float areaCylinder;//圆柱表面积
float othersideV; //圆柱侧边面积
int H; //圆柱高
float V; //圆柱体积
void cal_area_circle()
{
S=pow(R,2)*3.14;
cout<<"The area of the circle is:"<<S<<endl;//S没问题
}
//输入高度H
void setH()
{
cout<<"please enter the height of the cylinder:";
cin>>H;
}
//计算圆柱表面积并输出
void cal_area_cylinder()
{
othersideV=2*3.14*R*H;//侧边面积
areaCylinder=2*S+othersideV;
cout<<"The area of the cylinder is:"<<areaCylinder<<endl;
}
//计算圆柱体积并输出
void cal_V_cylinder()
{
V=H*S;
cout<<"The volumn of the cylinder is:"<<V<<endl;
}
};
int main()
{
Circle circle;
Cylinder cylinder;
//输入环节
circle.setR();
cylinder.setH();
//输出环节
cylinder.cal_area_circle();//求底面圆的面积
cylinder.cal_area_cylinder();//求圆柱体表面积
cylinder.cal_V_cylinder();//求圆柱体体积
system("pause");
return 0;
}