March 28, 2015

Homework Help: C++

Posted by Anonymous on Friday, November 26, 2010 at 10:19pm.

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.

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

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;

maximum = rainfall[0];
if (rainfall[k] > maximum)
maximum = rainfall[k]; //find maximum rainfall value
mamo = k; //month with max rainfall

{cout<<"Maximum rainfall month: "<<monthnames[mamo]<<endl;}

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


Answer this Question

First Name:
School Subject:

Related Questions

Programming logic and design - Design a program that lets the user enter the ...
math - Inches 9 8 - 7 - 6 - 5 - ,--- 4 - t-- ,--- 3 - t-- ,--- ~ t-- 2 1 - - J F...
Check my math please - Total Rainfall = rainfall mm x area covered In order to ...
Programming - Language - PYTHON Design a program that calculates the total ...
Programming - Design a program that calculates the total amount of a meal ...
Computer Programming Design - I really need someone to help me with this.I post ...
Intro to programming - Tip, Tax and Total question? Design a program that ...
CIS Design and Programming - Design a program that calculates the total amount ...
Programming - Design a program in pseudocode that calculates the amount of money...
programming - a sales report. Each record in the file contains a customer's ...