Create an application that computes the average monthly rainfall, number of mont
ID: 3547474 • Letter: C
Question
Create an application that computes the average monthly rainfall, number of months with above average rainfall, and the number of months with below average rainfall, given the rainfall amounts for each month in a year. Your program must read in and store in an array, the monthly rainfall amounts entered by the user one by one. Your program must accumulate the total annual rainfall amount as the monthly rainfall amounts are entered by the user. At the end of input, compute the average monthly rainfall. Then compare this average with each month
Explanation / Answer
Module Module1
Sub Main()
Dim sngRainfall(12) As Double
Dim sngAvgRainfall As Double
Dim sngAboveAvgCount As Integer = 0
Dim sngBelowAvgCount As Integer = 0
Dim TotalRainfall As Double = 0
For K = 1 To 12
Console.Write("Enter rainfall for month " & K & " : ")
sngRainfall(K) = Console.ReadLine()
TotalRainfall += sngRainfall(K)
Next K
sngAvgRainfall = CSng(TotalRainfall / 12)
For K = 1 To 12
If sngRainfall(K) >= sngAvgRainfall Then
sngAboveAvgCount += 1
ElseIf sngRainfall(K) < sngAvgRainfall Then
sngBelowAvgCount += 1
Else
End If
Next
Console.WriteLine("Total yearly rainfall amount = " & TotalRainfall)
Console.WriteLine("Average monthly rainfall amount = " & sngAvgRainfall)
Console.WriteLine("Number of months with above average rainfall = " & sngAboveAvgCount)
Console.WriteLine("Number of months with below average rainfall = " & sngBelowAvgCount)
Console.WriteLine("Press ENTER to close window")
Console.ReadLine()
End Sub
End Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.