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

I am having trouble with the code below. It displays 0s for the calculated total

ID: 3531500 • Letter: I

Question

I am having trouble with the code below. It displays 0s for the calculated total and average. Also 0s for the min and max.

Create an application that lets the user enter the rainfall for each of 12 months into an array. The application should calculate and display the following statistics: total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts of rainfall.

PublicClass Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

lstRainfall.Items.Clear()

TextBox1.Text =

""

TextBox2.Text =

""

TextBox3.Text =

""

TextBox4.Text =

""

End Sub

Private Sub btnRainfall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRainfall.Click

'calculate and display monthly rainfall

Dim strMonths() As String = {"January", "February", "March", "April", _

"May", "June", "July", "August", "September", "October", "November", _

"December"}

Dim intCount As Integer 'loop counter

Dim intRain As Integer 'amount of rain

Dim intMonths(11) As Integer

lstRainfall.Items.Add(

"Monthly Rainfall Input")

lstRainfall.Items.Add(

"-----------------------------------")

'get the rain for each month

For intCount = 0 To 11

intRain =

CInt((InputBox("Enter the inches of rainfall for" & " " & strMonths(intCount))))

lstRainfall.Items.Add((intRain).ToString() &

" for " & strMonths(intCount))

intMonths(intCount) = intRain

Next intCount

'get the rain for each month

Do While intCount <= 11

Try

intRain =

CInt(Val(InputBox("Please Enter the amount of Rainfall in Inches for " & strMonths(intCount))))

lstRainfall.Items.Add((intRain).ToString() &

" for " & strMonths(intCount))

intMonths(intCount) = intRain

intCount += 1

Catch

MsgBox("Enter a valid numeric value.")

End Try

Loop

End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

Dim strMonths() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",

"December"}

Dim intMonths(12) As Integer

Dim intCount As Integer

Dim intMaximum As Integer = intMonths(0)

Dim intMinimum As Integer=intMonths(0)

Dim dblAverage As Double

Dim intTotal As Integer = 0

Dim minIndex As Integer = 0

Dim maxIndex As Integer = 0

'calculate maximum

For intCount = 0 To (intMonths.Length - 1)

If intMonths(intCount) > intMaximum Then

intMaximum = intMonths(intCount)

maxIndex = intCount

End If

Next intCount

'calculate(minimum)

For intCount = 0 To (strMonths.Length - 1)

If intMonths(intCount) < intMinimum Then

intMinimum = intMonths(intCount)

minIndex = intCount

End If

Next intCount

'calculate total rainfall

For intCount = 1 To (strMonths.Length - 1)

intTotal += intMonths(intCount)

Next intCount

'use floating-point division to compute the average

dblAverage = (intTotal / strMonths.Length)

TextBox1.Visible =

True

TextBox2.Visible =

True

TextBox3.Visible =

True

TextBox4.Visible =

True

TextBox1.Text =

"The average monthly rainfall was " & dblAverage.ToString("n2")

TextBox2.Text =

"The total annual rainfall was " & intTotal

TextBox3.Text ="The minimum monthly rainfall was " & intMinimum & "(" & strMonths(minIndex) & ")"

TextBox4.Text ="The maximum monthly rainfall was " & intMaximum & "(" & strMonths(maxIndex) & ")"

End Sub

Private Sub lstRainfall_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstRainfall.SelectedIndexChanged

End Sub

End

Class

Explanation / Answer

download from herehttp://ww2.justanswer.com/uploads/ComputersGuru/2011-03-27_024851_rainfallstatistics.zip