Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles.
Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. Once the user has entered the rainfall for all the months, the program should calculate and display (in this order): The total rainfall for the year The average monthly rainfall The months with the highest and lowest amounts Note: Numeric values should be displayed using default precision. Do not use format specifiers to specify precision. Input Validation: Do not accept a negative number for any of the monthly rainfall amounts. If the user enters a negative value, the program should print the following string (exactly as it is shown here): "invalid data (negative rainfall) -- retry" and then immediately read the value again as input. The following sample run shows how your program's output must appear. The user's input is shown in bold. Sample Run: Enter rainfall for January: 1 Enter rainfall for February: 2 Enter rainfall for March: 3 Enter rainfall for April: 4 Enter rainfall for May: 5 Enter rainfall for June: 6 Enter rainfall for July: 7 Enter rainfall for August: 8 Enter rainfall for September: 9 Enter rainfall for October: 10 Enter rainfall for November: 11 Enter rainfall for December: 12 Total rainfall: 78 Average rainfall: 6.5 Least rainfall in: January Most rainfall in: December
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The image you sent describes a program that calculates rainfall statistics for the year Heres the code for this program in Python Python def main Gets rainfall data for each month calculates total and ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started