Quote Originally Posted by superfox1
The first problem is I have written a program that will allow users to enter any number of rainfall amounts. I need it to calculate and display the total rainfall amount and the average rainfall amount. I have to break it down into 2 seperate functions.

code seems like vb.net but still very similar
or your teacher is reallllly picky haha


hrm no arrays? haha ok still very doable
well first thing is that you mixed up your variable passing in the function (byref and byvals) when you pass a variable to a procedure with byref, you can fuck with the value and what not, but if you send it byval, then once you're out of the procedure then shit restores back to normal.


i'm assuming rainaccum is the value inputed
why not make a variable called avg1
also totalrain

try something along these lines:

Option Explicit On
Option Strict On

first thing first the variables: declare avg1, rainaccum, and totalrain and initialize 'em to 0.


Public Class MainForm

Private Function CalcAverage(ByVal rainaccum As Integer, ByRef avg1 As Integer)
' Calculates average rainfall amount
avg1 = (rainAccum + avg1) / 2 ((just get add the value of the entered info the the existing average, and then divide out, much like we do with grades haha)
Return avg1
Call CalcAverage(rainAccum, avg1) [why not call the function from the click event ... it doesnt specify what type of function was needed]
End Function
ok so now whenever you call calcaverage with those parameters, it'll take the current average, add the new value to it, then divide by two, giving you the current average

Private Function CalcTotal(ByRef TotalRain As Decimal, ByVal rainAccum As Decimal)
' calculates the total
totalrain = totalrain + rainAccum

Return totalrain

Call CalcTotal(totalrain, rainAccum)[same as above]

End Function



if u still aren't following:

make the procedure for the button pass the .text property of the textbox to the variable rainaccum

then in that sub, call calcaverage and pass rainaccum and avg1 to it
it'll calculate

then call calc total with totalrain and rain accum passed to it




after all thats done, in the sub for the click event on the button,
make it output the data however you do it
like label1.caption = aksldajsdk or whatever

and make it do what you want


but yeah Its late so i'm sure i overlooked something but yeah as for the second one it looks long i dont even feel like reading it