请教一个有关字符类型的题

当我输入整数的时候运行没有问题,但输入浮点数的时候就有奇奇怪怪的问题,请问这个应该改怎么改呢


#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;
}

img

img

你把R定义成int型,当然输入不了浮点数了
你的H也是个int型
为什么要定义成int

把int型换成float型也不行,错的更离谱了

img