What's wrong with double variable

1

I need to make an algorithm that the user informs two values and return the largest between them using double, but at the time of compiling it from the error pointing something in the double but I do not know how to solve, someone can help me and explain me how I would use correctly ?

#include <stdio.h>
double maior(double *x, double *y)    
{  
    double maior;   

    if (*x>*y)
    {
        maior=*x;
        return maior;
    }

    else
    {
        maior=*y;
    }

    return maior;
}



int main()  
{   

    double x,y,m;

    printf("Informe dois valores com espaco entre eles:");
    scanf("%f %f",&x,&y);

    m=maior(&x,&y);

    printf("O maior eh: %f \n",m);


    return 0;
}
    
asked by anonymous 29.05.2018 / 23:18

1 answer

6

The problem that is happening is due to the fact that you are trying to return a double variable in a function that was supposed to return int . To return double, change the return type of the function to double:

double maior(double *x, double *y) {  
    double m;   

    if (*x>*y)
    {
        m=*x;
        return m;
    }

    else
    {
        m=*y;
    }

    return m;
}

printf("O maior é: %f\n", m); // Faltou o formatador

Just adding, your function could be reduced to the following code:

double maior(double x, double y) {
    if(x < y)
        return y;
    return x;
}
    
29.05.2018 / 23:25