我刚开始学c++,用的是编程环境vc++下面这个程序是为了实现:输入10个数字,从中找出最大的,第二大的,最小的和第二小的数字。问题是结果只输出最大的和最小的数字。
cout << "The sub maximum number is " << submax << endl;
cout << "The sub minimum number is " << submin << endl;
这两行没有显示。我是新手,不要嘲笑我。下面是运行的结果:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Input the number 12
Input the next number 13
Input the next number 13
Input the next number 213
Input the next number 4234
Input the next number 234
Input the next number 341
Input the next number 123
Input the next number 234
Input the next number 234
The maximum number is 4234
The minimum number is 12
Press any key to continue
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
这是源程序:*************************************#include <iostream.h>int submax()
{
int counter=2,
present=0,
max=0,
min=0,
submax=0,
submin=0; cout << "Input the number ";
cin >> present;
max = min = submax = submin = present; while (counter <= 10){
cout << "Input the next number ";
cin >> present;
if (present > max) {
submax = max;
max = present;
}
else if (present < min){ 
submin = min;
min = present;
}
++counter;
} cout << "The maximum number is " << max << endl;
cout << "The minimum number is " << min << endl;
cout << "The sub maximum number is " << submax << endl;
cout << "The sub minimum number is " << submin << endl; return 0;
}*************************************

解决方案 »

  1.   

    The maximum number is 4234
    The minimum number is 12这不是输出了嘛?
      

  2.   

    我编译了好像输出完整:
    Input the number 231
    Input the next number 3
    Input the next number 231
    Input the next number 432
    Input the next number 54
    Input the next number 232
    Input the next number
    42
    Input the next number 432
    Input the next number 432
    Input the next number 2
    The maximum number is 432
    The minimum number is 2
    The sub maximum number is 231
    The sub minimum number is 3
      

  3.   

    是啊
    我也觉得很奇怪
    刚才我又试了一下
    还是只输出
    The maximum number is 4234
    The minimum number is 12没有输出
    The sub maximum number is 231
    The sub minimum number is 3不懂啊
    我用的是windows xp + visual c++ 6.0 + sp5 + processor packet
      

  4.   

    我换用了dev c++ 问题解决了 奇怪