Working Out Averages in Visual Basic
Dim average As Single ' this makes the "average" variable.
Dim total As Single ' this makes your "total" variable.
Dim number1 As Single ' this makes "your first numbers" variable.
Dim number2 As Single ' this makes "your second numbers" variable.
Dim number3 As Single ' this makes "your third numbers" variable.
number1 = InputBox("What's the first number?") ' this asks for your first number.
number2 = InputBox("What's the second number?") ' this asks for your second number.
number3 = InputBox("What's the third number?") ' this asks for your third number.
total = number1 + number2 + number3 ' this calculates your total number by adding all three numbers together.
average = total / 3 ' this calculates your average by diving your total number by 3
MsgBox("your average is: " & average) ' this displays "your average is:" *and then your average number
There is also a shorter way to calculate the average!
total = number1 + number2 + number3 ' The Long way to calculate the average.
average = total / 3 ' The Long way to calculate the average.
------------------------------------------------------------------------------------------------------------
average = number1 + number2 + number3 / 3 ' This is the short way to calculate the average in one line.
If there are any issues, feel free to contact me!
itshyperion@gmail.com
Lovely x