//Stores monthly rainfall amounts in an array
//Displays the monthly rainfall amounts, the
//total annual rainfall amount, the average rainfall
//amount, the highest rainfall amount, and the
//lowest rainfall amount
//Created/revised by
#include
using std::cout;
using std::cin;
using std::endl;
//function prototypes
void displayMonthly(double []);
void displayTotal(double []);
void displayAvg(double []);
void displayHigh(double []);
void displayLow(double []);
int main()
{
//declare variable and array
int choice = 0;
double rainfall[12] = {0.0};
//get rainfall amounts
for (int x = 0; x < 12; x += 1)
{
cout << "Enter rainfall for month " << x + 1 << ": ";
cin >> rainfall[x];
} //end for
do
{
//display menu and get menu choice
cout << endl;
cout << "1 Display monthly amounts" << endl;
cout << "2 Display total amount" << endl;
cout << "3 Display average amount" << endl;
cout << "4 Display highest amount" << endl;
cout << "5 Display lowest amount" << endl;
cout << "6 End program" << endl;
cout << "Enter your choice: ";
cin >> choice;
//call appropriate function or end program
if (choice == 1)
displayMonthly(rainfall);
else if (choice == 2)
displayTotal(rainfall);
else if (choice == 3)
displayAvg(rainfall);
else if (choice == 4)
displayHigh(rainfall);
else if (choice == 5)
displayLow(rainfall);
//end ifs
} while (choice >= 1 && choice <= 5);
return 0;
} //end of main function
void displayMonthly(double rainfall[])
{
int i;
for (i=0;i<12;i++)
{
cout<<"month "< }
} //end of displayMonthly function
void displayTotal(double rainfall[])
{
int i;
double sum=0;
for (i=0;i<12;i++)
{
sum+=rainfall[i];
}
cout<<"the total rainfall is "<
}//end of displayTotal function
void displayAvg(double rainfall[])
{
int i;
double sum=0;
for (i=0;i<12;i++)
{
sum+=rainfall[i];
}
cout<<"the average rainfall is "<
void displayHigh(double rainfall[])
{
int i;
double max=0;
for (i=0;i<12;i++)
{
if (rainfall[i]>max)
max=rainfall[i];
}
cout<<"the highest rainfall is "<
void displayLow(double rainfall[])
{
int i;
double min=999999;
for (i=0;i<12;i++)
{
if (rainfall[i]
}
cout<<"the lowest rainfall is "<
去试吧。
是这样吗
void displayMonthly(double rainfall[])
{
int i;
for (i=0;i<12;i++)
{
cout<<"month "< }
} //end of displayMonthly function
void displayTotal(double rainfall[])
{
int i;
double sum=0;
for (i=0;i<12;i++)
{
sum+=rainfall[i];
}
cout<<"the total rainfall is "<
}//end of displayTotal function
void displayAvg(double rainfall[])
{
int i;
double sum=0;
for (i=0;i<12;i++)
{
sum+=rainfall[i];
}
cout<<"the average rainfall is "<
void displayHigh(double rainfall[])
{
int i;
double max=0;
for (i=0;i<12;i++)
{
if (rainfall[i]>max)
max=rainfall[i];
}
cout<<"the highest rainfall is "<
void displayLow(double rainfall[])
{
int i;
double min=999999;
for (i=0;i<12;i++)
{
if (rainfall[i]
}
cout<<"the lowest rainfall is "<
int Sort(struct Student ar[], int len)
{
int i,j;
struct Student tmp;
for(i = 0; i < len -1; ++i)
for(j = i; j < len; ++j)
{
if(ar[i].point < ar[j].point)
{
tmp = ar[i];
ar[i] = ar[j];
ar[j] = tmp;
}
}
//for(i = 0; i < len; ++i)
//{
// printf("%d %20s %-7.2f \n", ar[i].number, ar[i].name, ar[i].point);
//}
}