#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int counter = 3;
int number1;
int number2 = 0;
int number3 = 0;
cout << "请输入第1个数" << endl;
cin >> number2;
cout << "请输入第2个数" << endl;
cin >> number3;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
while ( counter <= 10 )
{
cout << "请输入第" << counter << "个数" << endl;
cin >> number1;
if ( number1 > number2 )
if ( number2 > number3 )
{
number2 = number1;
number3 = number2;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
else if ( number1 > number3 )
{
number2 = number1;
number3 = number3;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
else
{
number2 = number3;
number3 = number1;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
else if ( number2 < number3 )
{
number2 = number3;
number3 = number2;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
else if ( number1 > number3 )
{
number2 = number2;
number3 = number1;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
else
{
number2 = number2;
number3 = number3;
cout << "目前最大的两个数为:" << number2 << " " << number3 << endl;
}
counter++;
}
return 0;
}
上面这段代码运行后,比如第一次输入12,第二次13,这两个是没什么问题的,第三次输入14,还是没有问题,第四次输入15,就会显示两个15,以后的奇数次输入都能正常显示最大的两个数,偶数次就不行,请问是什么原因,高手指点下!!