小编Pen*_*111的帖子

用于计算圆锥体积的C++程序

我编译此代码时遇到问题但是它运行不正常.这是我的源代码:

#include <iostream>

#include <cmath>

using namespace std; 

int main(){
    float height;
    float radius;
    float volume;

    volume=.3333333333333333333333333333333*radius*radius*height;


    cout<<"Enter height:"<<endl;
    cin>>height;
    cout<<"Enter radius:"<<endl;
    cin>>radius;

    if(height==0&&radius==0){
        cout<<"Not a valid solution";

    }

    if(height==0&&radius!=0){
        cout<<"not a valid a solution"<<endl;


    }

    if(height!=0&&radius==0){

        cout<<"not a valid solution"<<endl;
    }

    if(height<0&&radius<0){

        cout<<"Not a valid solution";
    }

    if(height<0&&radius>0){

        cout<<"Not a valid solution";
    }

    if(height>0&&radius<0){

        cout<<"Not a valid solution";
    }
    if(height>0&&radius>0){
        cout<<"Volume is "<<volume<<endl;

    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但当我运行它并要求我输入半径和高度的值时,音量始终为零:这就是我的意思:

Enter height:
9.0
Enter radius:
9.0
Volume is 0
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c++

-3
推荐指数
1
解决办法
1052
查看次数

标签 统计

c++ ×1