双打似乎不起作用。我只能使用int吗?
听说可以用C++函数模板把这个改成double。我不知道该怎么做。
#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;
}
所以问题是
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);
}
无论如何,现在我遇到了一个新错误...说 maxim is nan... 解决了。谢谢大家!