| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

#include<iostream>
#include "string"
using namespace std;
int main()
{
float A;
float B;
float C;
cout<<"请输入A的体重"<<endl;
cin>>A;
cout<<"请输入B的体重"<<endl;
cin>>B;
cout<<"请输入C的体重"<<endl;
cin>>C;
cout<<"A的体重"<<A<<endl;
cout<<"B的体重"<<B<<endl;
cout<<"C的体重"<<C<<endl;
if (A>B)
{
if (B>=C)
{cout<<"最重的猪是:A1"<<endl;}
else
{
if(A>C)
{cout<<"最重的猪是:A2"<<endl;}
else if (A=C)
{cout<<"最重的猪是:AC3"<<endl;}
else
{cout<<"最重的猪是:C4"<<endl;}

}
}
else if(A=B)
{
if(A>C)
{cout<<"最重的猪是:BA5"<<endl;}
else if(A=C)
{cout<<"最重的猪是:BAC6"<<endl;}
else if(A<C)
{cout<<"最重的猪是:C7"<<endl;}
}
else
{
if (B=C)
{cout<<"最重的猪是:BC8"<<endl;}
else if(B<C)
{cout<<"最重的猪是:C9"<<endl;}
else
{cout<<"最重的猪是:B10"<<endl;}
}
system("pause");
return 0;
}

```#include <iostream>
#include <string>
using namespace std;

int main( void )
{
double a, b, c;
cout << "请输入A的体重: ";
cin >> a;
cout << "请输入B的体重: ";
cin >> b;
cout << "请输入C的体重: ";
cin >> c;
cout << "A的体重" << a <<endl;
cout << "B的体重" << b <<endl;
cout << "C的体重" << c <<endl;

double heaviest = a;
string heaviest_list = "A";
if( b == heaviest )
{
heaviest_list.push_back( 'B' );
}
else if( b > heaviest )
{
heaviest = b;
heaviest_list = "B";
}
if( c == heaviest )
{
heaviest_list.push_back( 'C' );
}
else if( c > heaviest )
{
heaviest = c;
heaviest_list = "C";
}
cout << "最重的猪是: " << heaviest_list << endl;
}```

```#include <iostream>
#include <string>
using namespace std;

int main( void )
{
double weights[3]; // 以后只需要改这个3就能适应更多数量的猪
for( size_t i=0; i!=std::size(weights); ++i )
{
cout << "请输入" << char('A'+i) << "的体重: ";
cin >> weights[i];
}

for( size_t i=0; i!=std::size(weights); ++i )
{
cout << char('A'+i) << "的体重: " << weights[i] << '\n';
}

double heaviest = weights[0];
string heaviest_list;
for( size_t i=0; i!=std::size(weights); ++i )
{
if( weights[i] == heaviest )
heaviest_list.push_back( char('A'+i) );
else if( weights[i] > heaviest )
{
heaviest = weights[i];
heaviest_list = char('A'+i);
}
}

cout << "最重的猪是: " << heaviest_list << endl;
}```

• 后卿2022-05-13 11:18 送鲜花  1朵   附言：多谢多谢，原来是=和==的问题
• 4
• 1/1页
• 1