Domanda

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;
}*/
È stato utile?

Soluzione

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){
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top