np!Originally Posted by admin
This isn't .net...not sure what the difference is...hehe shows how much I know about it!
np!Originally Posted by admin
This isn't .net...not sure what the difference is...hehe shows how much I know about it!
There's no trim like a 50 trim....oh wait!
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.
This is what I have so far:
Option Explicit On
Option Strict On
Public Class MainForm
Private Function CalcAverage(ByRef raincounter As Integer, ByRef rainAccum As Integer, ByVal avgRain As Integer)
' Calculates average rainfall amount
avgRain = (rainAccum + raincounter) / 2
Return avgRain
Call CalcAverage(rainAccum, raincounter)
End Function
Private Function CalcTotal(ByVal rainCounter As Decimal, ByVal rainAccum As Decimal) As Decimal
' calculates the total
rainAccum = rainCounter + rainAccum
Return rainAccum
Call CalcTotal(rainCounter, rainAccum)
End Function
Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
Me.Close()
End Sub
Private Sub xMonthlyTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xMonthlyTextBox.KeyPress
' accept numbers, the period, and the Backspace
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub xMonthlyTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xMonthlyTextBox.TextChanged
Me.xTotalLabel.Text = String.Empty
Me.xAverageLabel.Text = String.Empty
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
Dim rainAccum As Decimal
Dim avgRain As Decimal
Me.xTotalLabel.Text = rainAccum.ToString("n2")
Me.xAverageLabel.Text = avgRain.ToString("n2")
End Sub
End Class
The next one I have to write a program that will allow users to enter in a 5 digit number with the 5th digit being the check digit. What needs to happen is the user enters in the 5 digit code...every other number is multiplied by 2...then add the numbers together, take the last digit and add it to the end of the first number set to check if it is the correct number...then I need it to display if it is correct or incorrect.
I know it sounds confusing..here is an example
Original number: 1357
multiply every other number by 2: 1 3 5 7
*2 *2
Results: 1 6 5 14
Add the numbers together: 1+6+5+14 = 26
new number: 13576
six would be my check digit.
Here is what I have so far:
Option Explicit On
Option Strict On
Public Class MainForm
Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
Me.Close()
End Sub
Private Sub xNumberTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumberTextBox.Enter
Me.xNumberTextBox.SelectAll()
End Sub
Private Sub xNumberTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xNumberTextBox.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub xNumberTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumberTextBox.TextChanged
Me.xMessageLabel.Text = String.Empty
End Sub
End Class
There's no trim like a 50 trim....oh wait!
i only read the top part, but to clarifyOriginally Posted by superfox1
you are trying to make a prog that will calculate the total and average rainfall amounts right?
in this function:
Private Function CalcAverage(ByRef raincounter As Integer, ByRef rainAccum As Integer, ByVal avgRain As Integer)
' Calculates average rainfall amount
avgRain = (rainAccum + raincounter) / 2
Return avgRain
Call CalcAverage(rainAccum, raincounter)
End Function
its referring to rain counter (i'm assuming thats the total number of entries added, and rainaccum = (rain accumulated?)= ?
I don't know about you but an easier way to do it would be to use an array man.
It would make everything so much easier for you. I'm not going to do your homework for you man but its mad easy just learn it.
Heres some pseudo code to point you into the right direction
declare an array (for the amount of rain)
in the procedure for the button, make it store the contents of the input box into a new element of this array
for example, say you have ran this prog, it will store
rain(0) = 5
rain(1) = 10
rain(2) = 7
ok got it? then the index(which is the number in the parenthesis of the variable) + 1 = the total number of entries you added right?
so add up all of the elements of the array, and divide by (index + 1) of the variable.
theres the average.
to calculate the rainfall total, just simply add up all of the elements of the array
I cant do an array...not allowed.... have to do two seperate functions to calculate the total and average rainfall. I am completely lost. This is an online class and the teacher never answers any emails. Very frustrating. I got it all untill I got to this last part..now it is like I'm looking at a Chineese dictionary.Originally Posted by RandomGuy
There's no trim like a 50 trim....oh wait!
code seems like vb.net but still very similarOriginally Posted by superfox1
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