#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.
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.