user13658181
user13658181

Reputation:

error: invalid conversion from ‘int (*)(int, int)’ to ‘int’ [-fpermissive]

I'm trying to create a program with functions that prints the smaller number between two numbers. But when i assign a function to a variable it shows this error:

error: invalid conversion from ‘int (*)(int, int)’ to ‘int’ [-fpermissive]

The code :

#include <iostream>
using namespace std;
int minimum(int num1, int num2){
    int min;
    if(num1 > num2)
        min = num1;
    else
        min = num2;
    return min;
}
int main()
{
    int c{100};
    int d{200};
    int result;
    result = minimum;
    cout<<"The smallest number is " <<result;;
}

And it also shows this error :

error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘’)

It'll be really helpful if you could give me a solution!

Upvotes: 0

Views: 1356

Answers (2)

SzymonO
SzymonO

Reputation: 596

That happens because you call the function without any parameters, also min is never created and your function currently checks for maximum number.

#include <iostream>
using namespace std;
int minimum(int num1, int num2) {
    int min;
    if (num1 < num2)
        min = num1;
    else
        min = num2;
    return min;
}
int main()
{
    int c{ 100 };
    int d{ 200 };
    int result = minimum(c, d);
    cout << "The smallest number is " << result;
}

Upvotes: 1

K.R.Park
K.R.Park

Reputation: 1149

I am pretty sure that you intended to use

result=minimum(c,d);

Additionally, inside the function definition, the direction of > should be changed to <.

Upvotes: 1

Related Questions