Question

Write a program that stores the total amount of rain for each month in an array....

Write a program that stores the total amount of rain for each month in an array. Prompt the user for the values for each month to load the array. Display this information back to them in a nice format with the name of the month and the rainfall for that month. Display back the total rainfall for the year, the average monthly rainfall, the month with the most rain, the month with the least rain, the months with rainfall above average, and the months with rainfall below average. Do not accept negative numbers from the user to be stored in the array.

Be sure to test your code with different values and to comment your code completely. Make sure your code is user friendly and the output is formatted nicely.

HINT: Break this problem up into pieces. For instance, load the array and display it back out. Get this to work first. Then add the functionality to display the total amount of rain. When that works add the next piece, and so on.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

void CollectRainData(double rainfallArr[],string months[],int size);
double CalculateTotalRainfall(double rainfallArr[],int size);
double CalculateAverage(double rainfallArr[],int size);
double FindLowest(double rainfallArr[],int size,int &smallestIndex);
double FindHighest(double rainfallArr[],int size,int &largestIndex);
int main()
{
   // Declaring char array
string months[] = { "January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December" };
// Declaring variables
int size = 12, largestIndex, smallestIndex;
double rainfallArr[size], total = 0.0, largest, smallest,average;
// Setting the precision to two decimal places
std::cout << std::setprecision(2) << std::fixed;
  
CollectRainData(rainfallArr,months,size);
total=CalculateTotalRainfall(rainfallArr,size);
average=CalculateAverage(rainfallArr,size);
smallest=FindLowest(rainfallArr,size,smallestIndex);
largest=FindHighest(rainfallArr,size,largestIndex);
// Displaying the total and average rainfall
cout << endl << "The total rainfall for the year was " << total << " inches." << endl;
cout << endl << "The average rainfall for the year was " << average << " inches." << endl;
// displaying in which months had the smallest and most rainfall
cout << months[smallestIndex] << " had the smallest rainfall, with " << smallest << " inches."
<< endl;
cout << months[largestIndex] << " had the most rainfall, with " << largest << " inches."
<< endl;

return 0;
}
void CollectRainData(double rainfallArr[],string months[],int size)
{
   double rainfall;
   // Getting the rainfall stats of 12 months in an array
for (int i = 0; i < size;)
{
cout << "Enter the rainfall of " << months[i] << ":";
cin >> rainfall;
if (rainfall < 0)
{
cout << "** Invalid.Must be Positive **" << endl;
continue;
}
else
{
rainfallArr[i] = rainfall;
i++;
}
}

}
double CalculateTotalRainfall(double rainfallArr[],int size)
{
   double total=0;
   // finding the highest ,lowest total rainfall
for (int i = 0; i < size; i++)
{
total += rainfallArr[i];
}
return total;
}
double CalculateAverage(double rainfallArr[],int size)
{
   double tot=CalculateTotalRainfall(rainfallArr,size);
   return tot/size;
}
double FindLowest(double rainfallArr[],int size,int &smallestIndex)
{
double smallest = rainfallArr[0];
for (int i = 0; i < size; i++)
{
   if (smallest > rainfallArr[i])
{
smallest = rainfallArr[i];
smallestIndex = i;
}

}
return smallest;
}
double FindHighest(double rainfallArr[],int size,int &largestIndex)
{
   double largest = rainfallArr[0];
   for (int i = 0; i < size; i++)
{
   if (largest < rainfallArr[i])
{
largest = rainfallArr[i];
largestIndex = i;
}

}
return largest;
}

__________________________

Output:


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Write a program that stores the total amount of rain for each month in an array....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that scores the total rainfall for each of 12 months into an array...

    Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...

  • Design a program that lets the user enter the total rainfall for each of 12 months...

    Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amount. PLEASE MODULARIZED THE CODE   PLEASE USE C PROGRAMMING AND ADD PSEUDOCODE

  • use vc++ to complete the programming project.... Number Array Version 1 (all interactive). Write a program...

    use vc++ to complete the programming project.... Number Array Version 1 (all interactive). Write a program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months. The program then prints out a nicely formatted table showing the rainfall for each of the previous 12 months as well as how much above or below average the rainfall was for each...

  • Write a C++ console application that allows your user to capture rainfall statistics. Your program should...

    Write a C++ console application that allows your user to capture rainfall statistics. Your program should contain an array of 12 doubles for the rainfall values as well as a parallel array containing the names of the months. Using each of the month names, prompt your user for the total rainfall for that month. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should...

  • The Problem Design a program that lets the user enter the total rainfall for each of...

    The Problem Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the number of months above and below the average rainfall, and the highest rainfall for each quarter of the year. The Assignment Write a Java program that contains five method/functions as follows: main(). Calls the functions enterRain, rainStats, aboveBelow, and quarterlyRain. enterRain(). Uses...

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • Directions: Write a code for the following programming exercise in PYTHON!!!!!!! -Design a program that lets...

    Directions: Write a code for the following programming exercise in PYTHON!!!!!!! -Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Here is what i got so far, but for some reason this code only print the Minimum and Maximum. its not printing the Average. def...

  • Your next programming assignment at the Research Center is to write a program that reads data...

    Your next programming assignment at the Research Center is to write a program that reads data from a file and produces a report of rainfall for that period of time. The program should read the starting month name from the data file, then read an ending month name, followed by reading in monthly rainfall amounts for each of the months from the starting month through the ending month. As it reads the monthly totals, it should sum (accumulate) the rainfall...

  • Write a program in C++ that lets the user enter the total rainfall for each of...

    Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.

  • qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a...

    qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a string array to hold the months of the year. Call it anything you want to just make sure it's a string array is at the end of the name, e.g. months). Create a DATA statement that holds the month names: DATA "jan","Feb", "Mar" etc. Next you'll need a FOR loop to READ the DATA into the array, Call a SUB to get the rainfall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT