incompatible pointer to integer conversion initializing 'int' with an expression of type 'int (void)'

#include <cs50.h>
#include <stdio.h>
int get_cents(void);
int calculate_quarters(int cents);


int main(void)
{

    //Ask how many cents the customer is owed
    int cents = get_cents;

    // Calculate the number of quarters to give the customer
    int quarters = calculate_quarters(cents);
    cents = cents - quarters * 25;

}

int get_cents(void)
{
    int cents;
    do
    {
      cents = get_int("Changed owed: ");
    }

    while (cents < 0);
    return cents;
}

int calculate_quarters(int cents)
{
 return 0;
}

incompatible pointer to integer conversion initializing ‘int’ with an expression of type ‘int (void)’ [-Werror,-Wint-conversion]
int cents = get_cents;

>Solution :

int cents = get_cents;

Here you are not really calling the function get_cents. You have to use parantheses like this:

int cents = get_cents(...);

The error is because get_cents is a pointer to that function and you are assigning the pointer to the int variable.

Leave a Reply