cin输入后不能直接判断吗语言-c++

img


#include
using namespace std;
int main(){

int a=0;
int b=0;
int c=0;
cout << "请输入三只小猪的重量"<< endl;
cin>>a;
cin>>b;
cin>>c;
if(a>b)
{
    if(a>c)
    {
        cout << "第一只小猪最重"<< endl;
    }else
    {
        cout << "第三只小猪最重"<< endl;
    };
}else
{
    if(b>c)
    {
        cout << "第二只小猪最重"<< endl;
    }
};

cout << "Hello, World!";
return 0;

}

你得拿变量存储这三个值才能进一步比较
你得问题在于多加了分号和a<=b的情况中少了b<=c的输出,也就是第三只最重的情况

img

#include<bits/stdc++.h>
using namespace std;

int main(){
int a=0;
int b=0;
int c=0;
cout << "请输入三只小猪的重量"<< endl;
cin>>a;
cin>>b;
cin>>c;
if(a>b)
{
    if(a>c)
    {
        cout << "第一只小猪最重"<< endl;
    }else
    {
        cout << "第三只小猪最重"<< endl;
    }
}else
{
    if(b>c)
    {
        cout << "第二只小猪最重"<< endl;
    }
    else
    {
        cout << "第三只小猪最重"<< endl;
    }
}

return 0;
}



23行的if少了else

#include<iostream> 
using namespace std;
int main(){
int a=0;
int b=0;
int c=0;
cout << "请输入三只小猪的重量"<< endl;
cin>>a;
cin>>b;
cin>>c;
if(a>b)
{
    if(a>c)
    {
        cout << "第一只小猪最重"<< endl;
    }else
    {
        cout << "第三只小猪最重"<< endl;
    }
}else
{
    if(b>c)
    {
        cout << "第二只小猪最重"<< endl;
    }else{
        cout<< "第三只小猪最重"<<endl;
    }
}

cout << "Hello, World!";
return 0;
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632