Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that reads the amount of rainfall in inches for each month o

ID: 3705842 • Letter: W

Question

Write a C++ program that reads the amount of rainfall in inches for each month of one-year from a file into an array. The file is named "rainfall.dat" and has 12 value, one for each month. (i.e. 5.92). After all of the values have been input, the program should calculate and output the following two statistics, with labels:
a. the total amount of rainfall for the year

b. which month has the highest rainfall (output the number, 1 for Jan, 2 for Feb, etc)

Please help with this quick problem! I want to make sure I'm doing this correctly.

Explanation / Answer

#include #include using namespace std; int main() { ifstream in("rainfall.dat"); int count = 0, max_month = 0; double max = 0, temp; double total = 0; double arr[12]; for(int i = 0; i < 12; ++i) { in >> temp; arr[i] = temp; } for(int i = 0; i < 12; ++i) { temp = arr[i]; if(temp > max) { max = temp; max_month = i+1; } total += temp; } cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote