以下代码将第二个数字输出为最大值。如果您需要任何其他信息,请告诉我。
#include <iostream>
#include <cstdlib>
using namespace std;
double *ComputeMaximum(const double *Max, const double *Min);
double *ComputeMaximum(const double *Max, const double *Min)
{
return ((double *)((&Max > &Min) ? Max : Min));
}
int main(void)
{
double *max;
double Initial, Secondary;
cout << "Enter the number followed by space then another number: ";
cin >> Initial;
cout << "\nIn-" << Initial;
cin >> Secondary;
cout << "\nSe-" << Secondary;
//cout >> "Of " >> Inital >> "and " >> Secondary;
//cout >> "the maximum is " >>
max = ComputeMaximum((double*)&Initial,(double*)&Secondary);
cout << "\nmax" << *max;
return 0;
}
下一个代码输出第一个数字作为最大值
#include <iostream>
#include <cstdlib>
using namespace std;
double *ComputeMaximum(const double *Max, const double *Min);
double *ComputeMaximum(const double *Max, const double *Min)
{
return ((double *)((Max > Min) ? Max : Min)); // Here is the difference(& missing)
}
int main(void)
{
double *max;
double Initial, Secondary;
cout << "Enter the number followed by space then another number: ";
cin >> Initial;
cout << "\nIn-" << Initial;
cin >> Secondary;
cout << "\nSe-" << Secondary;
//cout >> "Of " >> Inital >> "and " >> Secondary;
//cout >> "the maximum is " >>
max = ComputeMaximum((double*)&Initial,(double*)&Secondary);
cout << "\nmax" << *max;
return 0;
}
做错了什么?我只需要最大值,而不是第二个或第一个输入。我得到了答案。谢谢你们。
这里是:
#include <iostream>
#include <cstdlib>
using namespace std;
double *ComputeMaximum(const double *Max, const double *Min);
double *ComputeMaximum(const double *Max, const double *Min)
{
return (double*)((*Max > *Min) ? Max : Min);
}
int main(void)
{
double *max;
double Initial, Secondary;
cout << "Enter the number followed by space then another number: ";
cin >> Initial;
cout << "\nIn-" << Initial;
cin >> Secondary;
cout << "\nSe-" << Secondary;
//cout >> "Of " >> Inital >> "and " >> Secondary;
//cout >> "the maximum is " >>
max = ComputeMaximum(&Initial, &Secondary);
cout << "\nmax" << *max;
return 0;
}