1
#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;
}

我正在尝试编写一个程序来查找三个不同输入整数的最大值和最小值以进行赋值,这是我第一次处理函数,我不明白错误的含义。

4

1 回答 1

2

您正在尝试传递min_of_threemax_of_three这是签名的函数指针:

整数(*)(整数,整数,整数)

期望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函数的参数。

于 2013-10-26T22:14:04.360 回答