'Hi all. I'm trying to create an application that computes the average monthly 'rainfall, number of months with above average rainfall, and the number of with 'below average rainfall, given the rainfall amounts for each month in a year. 'is what I have so far.
Sub Main()
Dim sngRainfall() As Single = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
Dim intTotalRainfall As Integer = 0
For K = 1 To 12
Console.WriteLine("Enter Rainfall for month " & K & ":")
sngRainfall(K) = Convert.ToSingle(Console.ReadLine())
intTotalRainfall += sngRainfall(K)
Next
'Calculate average rainfall with the formula: average = total / 12
Compute AvgRainfall as TotalRainfall divided by 12
‘Initialize the above/below average counts to zero to reduce miscalculations
Initialize AboveAvgCount and BelowAvgCount to zero
'Using a for loop again compare the average rainfall to each monthly rainfall
'and count the above-rainfall months and below-rainfall months.
'use twelve iterations once again since asked the user for twelve variables.
'must use another loop since average couldn't be calculated when first
'loop was processed.
For K ranging from 1 to 12
'If the current rainfall amount in the loop denoted by the 'k'location in the array
' is greater than the average.
If Rainfall( K) > AvgRainfall then
'Then add one to the above average count.
Increment AboveAvgCount by 1
'Otherwise, if the rainfall amount for the current 'k' location in the array
'is less than the average.
else if Rainfall(K) < AvgRainfall then
'Then add one to the below average count.
Increment BelowAvgCount by 1
'Otherwise if the rainfall amount isn't greater or less than the average so...
else
'Just ignore that amount and don't count it towards either count variable.
Continue
'end the if statement after deciding the current value is above or below average
End of if statement
'end our for loop after having traversed all twelve values of rainfall array.
End of For loop
'Display the computed results that were able to calculate including the total, average,
'and above/below average counts to the user for review.
Display TotalRainfall, AvgRainfall, AboveAvgCount, and BelowAvgCount with suitable messages.
murdoc311 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
murdoc311 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
murdoc311 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
murdoc311 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.