我正在尝试这种方式。似乎更简化了。现在只是想弄清楚如何包含月份名称并让程序输出最下雨月份的名称而不是用户输入的数字。
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int a[12];
int x;
for (x=0; x<12; x++)
{
cout << "Insert days of rainfall for month "<<x+1<<endl;
cin >>a[x];
}
int max;
int min;
max = a[0];
min = a[0];
int e=0;
while (e<12)
{
if (a[e]>max)
{
max = a[e];
}
else if (a[e]<min)
{
min = a[e];
}
e++;
cout<<"The rainiest month was " <<max<<endl;
cout<<"The least rainy month was " <<min<<endl;
getch ();
return 0;
}
system("PAUSE");
return EXIT_SUCCESS;
}