Results 1 to 11 of 11

Thread: Finding out which integer is smallest

Hybrid View

  1. #1
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Finding out which integer is smallest

    What is even in the chapter? We can't really say anything before knowing that. It's probably just asking you to have some nested if's. Even perhaps something like:
    C++ Code:
    1. int smallest = a;
    2.  
    3. if (b < a)
    4.     smallest = b;
    5. if (c < b)
    6.     smallest = c;
    7. if (c < a)
    8.     smallest = c;
    ..etc.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  2. #2

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    51

    Re: Finding out which integer is smallest

    Write a program that inputs three integers from the keyboards and prints the sum, average,
    product, smallest and largest of these numbers.

    anyone else?? I'm stuck on telling which number is smallest.
    My questions might look stupid to others. After all I am still in the process of learning Visual Basic.

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: Finding out which integer is smallest

    Find the minimum of two values; then find the minimum of your selected minimum and the other value.

    If you had a function MIN(a,b) which returned the lesser of two values:

    Code:
    int a, b, c;
    
    min = MIN(a, b);
    min = MIN(min, c);
    
    // min is the minimum value.

    your min function might do this:

    Code:
    if (a < b)
      return a; // a is less than b
    else
      return b; // b is less than a OR a = b (they are both the 'min')
    Hope this helps!
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    51

    Re: Finding out which integer is smallest

    Quote Originally Posted by sunburnt
    Find the minimum of two values; then find the minimum of your selected minimum and the other value.

    If you had a function MIN(a,b) which returned the lesser of two values:

    Code:
    int a, b, c;
    
    min = MIN(a, b);
    min = MIN(min, c);
    
    // min is the minimum value.

    your min function might do this:

    Code:
    if (a < b)
      return a; // a is less than b
    else
      return b; // b is less than a OR a = b (they are both the 'min')
    Hope this helps!
    I'm srry I haven't gotten to that stuff yet and in the chapter it says i'm only suppose to use what I have learned so far. Is there like an equation or something to find out which of the numbers given is smallest?
    My questions might look stupid to others. After all I am still in the process of learning Visual Basic.

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