Finding the 2 Largest Values from 3 Inputs

  • Thread starter Thread starter taxi
  • Start date Start date
AI Thread Summary
The discussion revolves around creating a program, referred to as "lmc," to output the two largest values from three inputs. One participant seeks assistance in determining the largest value among three inputs, having already mastered finding the largest of two. A response provides a C++ function to find the maximum of three values, demonstrating that once the largest value is identified, deriving the two largest values becomes straightforward. The conversation also touches on the potential for applying this logic to more complex objects through class and operator overloading. Additionally, there is a request for clarification on what "lmc" stands for, with a link to a Wikipedia page about the Little Man Computer for further context.
taxi
Messages
2
Reaction score
0
hi.

i'm trying to make an lmc that gives oupts the 2 largest values from 3 inputs.

i know how to find out the largest from 2 values but can't think of how to get the largest from 3 inputs.

any help would be appreciated

thanks
 
Technology news on Phys.org
I have no idea what an "lmc" program is. Could you elaborate on that?

Regardless, returning the largest pair of three given values is trivial. I'll give you a hint how to write a function that will return the largest single value from three values; writing a function to return the largest two values should then be easy for you. I'll write it in C++ for the sake of argument.

Code:
double max(const double& a, const double& b, const double&c)
{
   double maxTempVariable = a;

   if (b > maxTempVariable)
      maxTempVariable = b;
   if (c > maxTempVariable)
      maxTempVariable = c;

   return maxTempVariable;
}

If you're interested in applying this to more general objects, classes together with appropriately overloaded relational operators is the ways to go.
 
shoehorn said:
I have no idea what an "lmc" program is. Could you elaborate on that?

Regardless, returning the largest pair of three given values is trivial. I'll give you a hint how to write a function that will return the largest single value from three values; writing a function to return the largest two values should then be easy for you. I'll write it in C++ for the sake of argument.

Code:
double max(const double& a, const double& b, const double&c)
{
   double maxTempVariable = a;

   if (b > maxTempVariable)
      maxTempVariable = b;
   if (c > maxTempVariable)
      maxTempVariable = c;

   return maxTempVariable;
}

If you're interested in applying this to more general objects, classes together with appropriately overloaded relational operators is the ways to go.

have a look at this.

http://en.wikipedia.org/wiki/Little_man_computer
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top