Hello, my programming project requires me to write an overloaded function max that takes two or three parameters and returns the largest of them. I'm having trouble with the program outputting the largest number, with my code below it just says the largest number is 0 no matter what numbers I input.
Can anyone help? Thanks!
#include <iostream>
using namespace std;
double max(double a, double b, double c);
int main()
{
double a, b, c;
cout << "Please input 2 or 3 numbers and the program will output\n";
cout << "the largest number." << endl << endl;
cin >> a >> b >> c;
cout << "The largest number is: " << max(a, b, c) << endl << endl;
system("pause");
return (0);
}
double max(double a, double b, double c)
{
if(a > b > c)
{
if(a > c > b)
{
return a;
}
}
else if (b > a > c)
{
if(b > c > a)
{
return b;
}
}
else if (c > a > b)
{
if(c > b > a)
{
return c;
}
}
}