Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of the two values. Define one of these functions to apply to type double, another to type int and a third to type char.

LANGUAGE: C++

CHALLENGE:

Write the definitions for three function named max. Each receives two parameters, of the same type, and returns the larger of the two values. Define one of these functions to apply to type double, another to type int and a third to type char.

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

2 Comments

  1. Matt on January 23, 2017 at 11:50 pm

    This function only has 1 input parameter and is named “Max” not max. Also, this function sets iHighest to 0, so you are always comparing your input to 0 and not to the other variable. This would also not be overloaded, as this is only one function with the given name.

    • Matt on January 23, 2017 at 11:52 pm

      Correct answer would be this:
      int max(int a, int b)
      {
      return ((a > b) ? a : b);
      }

      double max(double a, double b)
      {
      return ((a > b) ? a : b);
      }

      char max(char a, char b)
      {
      return ((a > b) ? a : b);
      }

Leave a Comment

You must be logged in to post a comment.