C++ !!!200+50

来源:百度知道 编辑:UC知道 时间:2024/09/20 18:45:56
our school can't enter chinese, we are haing an online test now, write a C++ program.
average rain fall
first, ask number of the years, then for each year, the program should ask the user to enter the inches of rain fall for that month(12 times in a year). the program should display the average for each year.finally the program should print out the total of rainfall in inches for the total number of years.at the end, the program will ask user either to proceed or to exit from the program.

use nested loops.
the outer loop will represent years and the inner loop will represent months.
don't accept input less than 1 for number of years and don't accept input as negative numbers for monthly rainfall
c++ not c!!!

time is up ....

#include <iostream>
using namespace std;

void main()
{
int years,rains=0;
char isContinue;

do
{
do
{
cout<<"Input number of the years:";
cin>>years;
}while(years<1);

for(int y=0;y<years;y++)
{
int const months=12;
int rain[months],total=0;

for(int m=0;m<months;m++)
{
do
{
cout<<"Input the inches of rain fall("<<y+1<<" year, "<<m+1<<" month):";
cin>>rain[m];
}while(rain[m]<0);
total+=rain[m];
}
cout<<"The average of rainfall in inches("<<y+1<<" year) is:"<<total/months<<endl;
rains+=total;
}
cout<<"The total of rainfall in inches (all years) i