Results 1 to 2 of 2

Thread: [RESOLVED] get the smallest and largest number using function inputbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    13

    Resolved [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

    Can someone help me pls or edit the code?

    Thnks,
    Junjun
    Attached Files Attached Files

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width