# C++

posted by .

I am having trouble identifying the flaws in my code. I need to created a program that calculates the rainfall for a given year in months. I needed it to show the total amount of rain for the year, the average monthly rainfall, and the months with the highest and lowest amounts. So far I got everything to calculate and display correctly all except the highest and lowest months. I have included the full code. Thanks.

#include<iostream>
using namespace std;

void main()
{
double rainfall[12], totalrainfall=0, avgrainfall =0, maximum =0, minimum=0;
int i,j,k,m,mimo, mamo;
char monthnames[12] = {'Jan','Feb','Mar','Apr','May','Jun','Juâ€¦

for (i=0;i<12;i++)
{
cout<<"Enter rainfall for month "<<i+1<<":";
cin>>rainfall[i]; //capture all rainfall values from user
}

for(j=0;j<12;j++)
{
totalrainfall = totalrainfall + rainfall[j]; //calculate total rainfall
}

cout<<"Total rainfall for the year:"<<totalrainfall<<endl;

avgrainfall = totalrainfall/12; //calculate average rainfall
cout<<"Average monthly rainfall: "<<avgrainfall<<endl;

for(k=0;k<12;k++)
{
maximum = rainfall[0];
if (rainfall[k] > maximum)
{
maximum = rainfall[k]; //find maximum rainfall value
mamo = k; //month with max rainfall
}
}

for(i=k;i<=k;i++)
{cout<<"Maximum rainfall month: "<<monthnames[mamo]<<endl;}

for(m=0;m<12;m++)
{
minimum = rainfall[0];
if (rainfall[m] < minimum)
{
minimum = rainfall[m];
mimo = m;
}
}
for(i=m;i<=m;i++)
{cout<<"Minimum rainfall month: "<<monthnames[mimo]<<endl;}

}

• C++ -

Don't know which version of C++ you use.
In general, string≠char, but
char * points to a string with a '\0' termination character.

You could use the string class, for monthnames, or use an array of pointers, such as:
char *monthnames[]={"Jan","Feb",...};
depending on whether you are allowed to use pointers.

I have not compiled your program to see if there are other problems. If you find other problems, post.

## Similar Questions

1. ### Math

1. Write 6.34 x 10 to the third power in a standard form. 2. Secondly, Find the amount of rain the state of North Carliona receives each year?
2. ### statistics

the average amount of rain per year in Greenville is 49 inches. the standard deviation is 8 inches. find the probability that nest year greeville will receive the following amount of rainfall. assume the variable is normally distributed. …
3. ### Programming logic and design

Design a program that lets the user enter the total rainfall for each 12 months into an array. The program should calculate and display the total rainfall for the year the average monthly rainfall, and the month with the highest and …
4. ### computer

to design a program that asks for the sales figures, computes the total sales for the year, and calculates and displays the average quarterly sales for the year
5. ### math

Inches 9 8 - 7 - 6 - 5 - ,--- 4 - t-- ,--- 3 - t-- ,--- ~ t-- 2 1 - - J F M A M J J A s 0 N D Months The graph above represents the amount of rainfall in a particular state by month. Which of the following is the total rainfall for …
6. ### programming

Design a program that calculates and displays the amount of money you would have if you invest \$5000.00 at 2 percent simple interest for one year. call a function and pass the needed data to do the calculation and return the result
7. ### Computer

Create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record …
8. ### computer science

create an algorithm, owchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record …
9. ### programing

create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record …
10. ### computer program

How do you design a program that asks for the sale figures, computes the total sales for the year, and calculates and displays final sale figures for the four quarters in 2010 and displays the average quarterly sale for the year?

More Similar Questions