Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

10. Average Rainfall (8 points) Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years.

image text in transcribed
image text in transcribed
image text in transcribed
10. Average Rainfall (8 points) Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Input Validation: Do not accept a number less than I for the number of years. eriod of years. How many years do you wish to average? umber of inches of rain For month 1P umber of inches of rain for msonth 3P umber of inches of rain for sonth6 Nmber of isches of rain for month 2 unber of inches of rain for sonth 4P umber of inches of rain for sonth 5 4 of inches of raim fer month 73 of inches of rain fer month ? 2 of inches of rain for sonth 9 4 for month 1? 5 of inches of rain for meeth 11 uber of inches of rain for month 12? 7 inches of rain for month 2P of inches of inches of inches ef of isches of rain fer month 12 Over peried of 24 CBoO F3 F5 P11 F7 11. Random Number Guessing Game (6 points) Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. n thinking of a number. Can you guess what it is? 50 No, that's too low Guess again: 75 No, that's too low. Guess again: 9e orry, that's too high. Guess again: 85 orry, that's too high. Guess again: 8 No, that's too low. Guess again: 83 Congratulations! You guessed it! was thinking of the number 83 12. Using Files-Numeric Processing (6 points) 12. Using Files-Numeric Processing (6 points) Download Random.txt file from Canvas, in the Assignment 02 folder. The Random.txt file contains a long list of random numbers. Copy the file to your hard drive and then write a program that opens the file, reads all the numbers from the file, and calculates the following A) The number of numbers in the file B) The sum of all the numbers in the file (a running total) C) The average of all the numbers in the file The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers. umber of numbers: 200 Slm of the numbers: 105527 Average of the numbers: 527.635 P5 F6 F2 F8 F9 10. Average Rainfall (8 points) Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period. Input Validation: Do not accept a number less than I for the number of years. eriod of years. How many years do you wish to average? umber of inches of rain For month 1P umber of inches of rain for msonth 3P umber of inches of rain for sonth6 Nmber of isches of rain for month 2 unber of inches of rain for sonth 4P umber of inches of rain for sonth 5 4 of inches of raim fer month 73 of inches of rain fer month ? 2 of inches of rain for sonth 9 4 for month 1? 5 of inches of rain for meeth 11 uber of inches of rain for month 12? 7 inches of rain for month 2P of inches of inches of inches ef of isches of rain fer month 12 Over peried of 24 CBoO F3 F5 P11 F7 11. Random Number Guessing Game (6 points) Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. n thinking of a number. Can you guess what it is? 50 No, that's too low Guess again: 75 No, that's too low. Guess again: 9e orry, that's too high. Guess again: 85 orry, that's too high. Guess again: 8 No, that's too low. Guess again: 83 Congratulations! You guessed it! was thinking of the number 83 12. Using Files-Numeric Processing (6 points) 12. Using Files-Numeric Processing (6 points) Download Random.txt file from Canvas, in the Assignment 02 folder. The Random.txt file contains a long list of random numbers. Copy the file to your hard drive and then write a program that opens the file, reads all the numbers from the file, and calculates the following A) The number of numbers in the file B) The sum of all the numbers in the file (a running total) C) The average of all the numbers in the file The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers. umber of numbers: 200 Slm of the numbers: 105527 Average of the numbers: 527.635 P5 F6 F2 F8 F9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions