error C2371: 'functionname' redefinition: different basic types

user2974830 picture user2974830 · Nov 9, 2013 · Viewed 30.7k times · Source

i have a Problem. I use Visual Studio 2013 and get the following Error:

Error C2371: 'getgrundflaeche' redefinition: different basic types.

I don't know why i get this Error. I get the same Error with VS12, when i try to call the function getgrundflaeche().

Here is the Code:

#include <stdio.h>
#define PI 3.14159265359

int main(void){
    double h = 0, d = 0, r = 0, G = 0, V = 0, M = 0, O = 0;

    printf("Geometrie Zylinder:\nBitte geben sie den Durchmesser d ein (cm): ");
    scanf_s("%lf", &d);
    printf("Bitte geben sie die Höhe h ein (cm): ");
    scanf_s("%lf", &h);
    r = d / 2;

    G = getgrundflaeche(r);
    /*V = get_volumen(r, h);
    M = get_mantelflaeche(d, h);
    O = get_oberflaeche(M, G); */

    system("CLS");

    printf("Eingaben:\nDurchmesser d: %lf cm\nHöhe h: %lf cm", d, h);
    system("PAUSE");

    return 0;
}

double getgrundflaeche(double r){
    return (r*r);
}
/*
double get_volumen(double r, double h){
return r*r*h*PI;
}

double get_mantelflaeche(double d, double h){
return d*h*PI;
}

double get_oberflaeche(double M, double G){
return M+2*G;
}*/

Answer

Paul Roub picture Paul Roub · Nov 9, 2013

You never declared getgrundflaeche before calling it. The compiler assumes undeclared functions return int. The later function definition is, of course, different.

Solve this by adding a declaration before main():

double getgrundflaeche(double r);

int main(void){