error C2664: 'print_result' : cannot convert parameter 1 from 'int (__cdecl *)(int,int,int)' to 'int'

StackOverflow https://stackoverflow.com/questions/19612471

Question

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

I'm trying to write a program that finds the maximum and minimum of three different inputted integers for an assignment, this is my first time dealing with functions and I don't understand what the error means.

Was it helpful?

Solution

You are trying to pass min_of_three and max_of_three that are function pointers of the signature:

int (*)(int, int, int)

to print_result which expects int arguments.

You want this:

print_result(min_of_three(x,y,z), max_of_three(x,y,z));

The functions min_of_three(x,y,z) and max_of_three(x,y,z) return int that is then used as parameters for the print_result function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top