Hello, I am working on a rainfall calculator. I keep getting the zeros for the totals (Minimum, Maximum, Average and Total Rainfall output). Everything else works as expected. Can you please help me with this?
vb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnInputMonthlyRainfall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputMonthlyRainfall.Click
' Calculate and display monthly rainfall input
' Reference??
Dim intCount As Integer ' loop counter
Dim intMonths(11) As Integer
Dim strMonths() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
Dim intRainfall As Integer ' Rainfall amount
lstRainfall.Items.Add("Monthly Rainfall Input")
lstRainfall.Items.Add("______________________")
'Rainfall for each month
For intCount = 0 To 11
intRainfall = (InputBox("Enter the amount of rainfall in inches for" & " " & strMonths(intCount)))
lstRainfall.Items.Add(strMonths(intCount) & " " & (intRainfall).ToString())
intRainfall = intMonths(11)
Next intCount
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 btnDisplayStats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayStats.Click
' Display Stats
Dim intCount As Integer
Dim intMonths(11) As Integer
Dim strMonths() As String = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
Dim intMaximum As Integer
Dim intMinimum As Integer
Dim dblAverage As Double
Dim intTotal As Integer = 0
'calculate maximum
For intCount = 1 To (intMonths.Length - 1)
If intMonths(intCount) > intMaximum Then
intMaximum = intMonths(intCount)
End If
Next intCount
'calculate(minimum)
For intCount = 1 To (strMonths.Length - 1)
If intMonths(intCount) < intMinimum Then
intMinimum = strMonths(intCount)
End If
Next intCount
'calculate average
For intCount = 0 To (strMonths.Length - 1)
intTotal += intMonths(intCount)
Next intCount
'use floating-point division to compute the average
dblAverage = (intTotal / strMonths.Length)
'calculate total rainfall
For intCount = 0 To (strMonths.Length - 1)
intTotal += intMonths(intCount)
Next intCount
'list output for stats
lblAnnualRainfall.Text = ("The total annual rainfall was " & intTotal.ToString())
lblAverageRainfall.Text = ("The average monthly rainfall was " & dblAverage.ToString())
lblMinimumRainfall.Text = ("The minimum monthly rainfall was " & intMinimum.ToString())
lblMaximumRainfall.Text = ("The maximum monthly rainfall was " & intMaximum.ToString())
lblAnnualRainfall.Visible = True
lblAverageRainfall.Visible = True
lblMinimumRainfall.Visible = True
lblMaximumRainfall.Visible = True
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clear all display fields
lblAnnualRainfall.Visible = False
lblAverageRainfall.Visible = False
lblMinimumRainfall.Visible = False
lblMaximumRainfall.Visible = False
End Sub
End Class
EDIT: Code blocks added, please use them in future posts =>
This post has been edited by PsychoCoder: 14 May, 2008 - 04:59 AM