doubles seem not to work. can I only use int?
I heard that I can use C++ function templates to change this to double. I'm not sure how to go about that though.
#include <iostream> // Necessary
using namespace std;
#define mMaxOf2(max, min) ((max) > (min) ? (max) : (min))
#define mMaxOf3(Min, Mid, Max)\
{\
mMaxOf2(mMaxOf2((Min), (Mid)),(Max))\
}
inline long double fMaxOf2(long double min, long double max)
{
return max > min ? max : min;
}
inline long double fMaxOf3(long double Min, long double Mid, long double Max)
{
return fMaxOf2(Min, fMaxOf2( Mid, Max));
//fMaxOf2(Min, fMaxOf2( Mid, Max)); caused nan problem
}
int main()
{
double primary;
double secondary;
double tertiary;
cout << "Please enter three numbers: ";
cin >> primary >> secondary >> tertiary;
cout << "The maximum of " << primary << " " << secondary << " " << tertiary;
long double maximum = mMaxOf3(primary, secondary, tertiary);
cout << " using mMaxOf3 is " << maximum;
cout << "\nThe maximum of " << primary << " " << secondary << " " << tertiary;
long double maxim = fMaxOf3(primary, secondary, tertiary);
cout << " using fMaxOf3 is " << maxim;
return 0;
}
So the problem was
inline long double fMaxOf2(long double min, long double max)
{
return max > min ? max : min;
}
inline long double fMaxOf3(long double Min, long double Mid, long double Max)
{
fMaxOf2(Min, fMaxOf2( Mid, Max)); // This was wrong
// It was fMaxOf2 (fMaxOf2(Min, Mid, Max);
}
Anyway now I get a new error... says maxim is nan... Solved it. Thanks Everyone!