[RESOLVED] get the smallest and largest number using function inputbox
hello everone.. I have homework using VB 6 so here is the problem:
Write a program that will input 3 different integers using Function InputBox and prints the sum; the average; the product; the smallest and largest of these numbers on the form using print. Use only If/Then Statement.
I had already made the sum, average and the product..but its kinda difficulty for me on how to get the smallest and largest numbers among those 3 numbers you entered.
when i enter 5, 25 and 50 the result below:
Sum is 80
Product is 6250
Average is 27
Smallest is 5
Largest is 25 <<<this should be 50 not 25
Re: get the smallest and largest number using function inputbox
Why not make it easier on yourself. Create 2 new variables: numSmall, numLarge
Code:
numSmall = num1
numLarge = num1
If num2 > numLarge Then
numLarge = num2
ElseIf num2 < numSmall Then
numSmall = num2
End If
If num3 > numLarge Then
numLarge = num3
ElseIf num3 < numSmall Then
numSmall = num3
End If
' now print numSmall and numLarge
Edited: If your instructor talked about error checking, you should use some.
1. What if a user mistakenly typed in alpha-characters into your inputbox?
2. Also, if num1,num2,num3 are very large numbers your sum and/or product calcs can cause an overflow error
3. Your average calc cannot be working correctly. Try it with numbers: 1,2,5. The average of 8/3 is 2.666... not 2.
Hint: don't use Integer for variable "a".
Last edited by LaVolpe; Dec 1st, 2009 at 08:55 AM.
Insomnia is just a byproduct of, "It can't be done"