#include<iostream>
using namespace std;
bool is_different(int x, int y, int z);
int max_of_three(int x, int y, int z);
int greater_of_two(int x, int y);
int min_of_three(int x, int y, int z);
int smaller_of_two(int x, int y);
void print_result(int min_of_three, int max_of_three);
int main ()
{
int x, y, z;
while(1==1)
{
cout << "Please input 3 different integers." << endl;
cin >> x >> y >> z;
if (is_different (x, y, z))
{break;}
}
print_result(min_of_three, max_of_three);//error here
}
bool is_different (int x, int y, int z)
{
if (x!=y && x!=z && y!=z)
{
return true;
}
else
{return false;}
}
int greater_of_two (int x, int y)
{
if (x > y)
return x;
if (y > x)
return y;
return 0;
}
int max_of_three (int x, int y, int z)
{
return greater_of_two(greater_of_two(x, y) , z);
}
int smaller_of_two (int x, int y)
{
if (x < y)
return x;
if (y < x)
return y;
return 0;
}
int min_of_three (int x, int y, int z)
{
return smaller_of_two(smaller_of_two(x, y) , z);
}
void print_result (int min_of_three, int max_of_three)
{
cout << "The minimum value of the three is " << min_of_three << endl;
cout << "The maximum value of the three is " << max_of_three << endl;
}
我正在尝试编写一个程序来查找赋值的三个不同输入整数的最大值和最小值,这是我第一次处理函数而我不明白错误的含义。
答案 0 :(得分:2)
您正在尝试传递作为签名的函数指针的min_of_three
和max_of_three
:
int(*)(int,int,int)
到期望print_result
个参数的int
。
你想要这个:
print_result(min_of_three(x,y,z), max_of_three(x,y,z));
函数min_of_three(x,y,z)
和max_of_three(x,y,z)
返回int
,然后将其用作print_result
函数的参数。