Conflicting types et de la déclaration précédente de x est ici...quoi?

J'ai enseigné moi-même C pour quelques mois, quand j'ai le temps, et j'ai couru dans un problème, je ne suis pas sûr de la façon de les corriger.

Plus précisément, lorsque j'essaie de le compiler avec gcc, j'obtiens:

de la géométrie.c:8: erreur: conflicting types for ‘trapèze’ 
la géométrie.c:7: remarque: la déclaration de "trapèze" a été ici 
la géométrie.c:48: erreur: conflicting types for ‘trapèze’ 
la géométrie.c:7: remarque: la déclaration de "trapèze" a été ici 
la géométrie.c:119: erreur: conflicting types for ‘trapezoid_area’ 
la géométrie.c:59: remarque: les précédentes déclaration implicite de " trapezoid_area’ est ici 
la géométrie.c: In function ‘cone_volume’: 
la géométrie.c:128: erreur: objet appelé ‘3.14100000000000001421085471520200371742248535156 e+0’ n'est pas une fonction 
la géométrie.c: In function ‘cylinder_volume’: 
la géométrie.c:136: erreur: objet appelé ‘3.14100000000000001421085471520200371742248535156 e+0’ n'est pas une fonction 

Maintenant, je pense que j'ai peut-être besoin de transtypage les fonctions, mais encore une fois, je ne suis pas sûr.

On dirait qu'il veut lire PI, que j'avais défini comme 3.141, comme une fonction. Est il possible que je peux éviter d'utiliser le nombre magique 3.141 (même si c'est beaucoup moins d'un nombre magique que d'autres)?

//Geometric formulae
#include <stdio.h>
#include <math.h>
#define PI 3.141
float trapezoid(float b1, float b2, float h);
int trapezoid();
float sphere_volume(float r);
int sphere();
float cone_volume(float r, float h);
int cone();
float pyramid_volume(float b, float h);
int pyramid();
float cylinder_volume(float r, float h);
int cylinder();
int main(void) {
char selection = 0;
while(selection != 'q') {
printf("\t--Geometric Formulas--\n");
printf("\tSelection an option from the menu: ");
scanf("%c", & selection);
switch(selection) {
case 1: //Trapezoid area
printf("%d", trapezoid());
break;
case 2: //Sphere volume
printf("%d", sphere());
break;
case 3: //Cone volume
printf("%d", cone());
break;
case 4: //Pyramid volume
printf("%d", pyramid());
break;
case 5: //Cylinder volume
printf("%d", cylinder());
break;
default:
break;
}
}
}
//     --Shape Menus--
//Trapezoid
int trapezoid() {
float h = 0, b1 = 0, b2 = 0;
float traparea;
printf("\tTrapezoid base 1: ");
scanf("%3f", &b1);
printf("\tTrapezoid base 2: ");
scanf("%3f", &b2);
printf("\tTrapezoid height: ");
scanf("%3f", &b2);
traparea = trapezoid_area(b1, b2, h);
printf("\tTrapezoid Area: %3f\n", traparea); }
//Sphere
int sphere() {
float r = 0;
float spherevol;
printf("\tSphere radius: ");
scanf("%f", &r);
spherevol = sphere_volume(r);
printf("\tSphere volume: %3f\n", spherevol); }
//Cone
int cone() {
float r = 0, h = 0;
float conevol;
printf("\tCone radius: ");
scanf("%f", &r);
printf("\tCone height: ");
scanf("%f", &h);
conevol = cone_volume(r, h);
printf("\tCone volume: %3f\n", conevol); }
//Pyramid
int pyramid() {
float b = 0, h = 0;
float pyramidvol;
printf("\tPyramid base: ");
scanf("%f", &b);
printf("\tPyramid height: ");
scanf("%f", &h);
pyramidvol = pyramid_volume(b, h);
printf("\tPyramid volume: %3f\n", pyramidvol); }
//Cylinder
int cylinder() {
float r = 0, h = 0;
float cylindervol;
printf("\tCylinder radius: ");
scanf("%f", &r);
printf("\tCylinder height: ");
scanf("%f", &h);
cylindervol = cylinder_volume(r, h);
printf("Cylinder volume: %3f", cylindervol); }
//     --Geometric Formulas--
//Trapezoid Area Computation
float trapezoid_area(float b1, float b2, float h) {
return ((b1 + b2) * h) / 2; }
//Sphere Volume Computation
float sphere_volume(float r) {
return ((pow(r,3)) * (4 * PI)) / 3; }
//Cone Volume Computatioin
float cone_volume(float r, float h) {
return ((PI(pow(r,2)) * h)) / 3; }
//Pyramid Volume Computation
float pyramid_volume(float b, float h) {
return (b * h) / 3; }
//Cylinder Volume Computation
float cylinder_volume(float r, float h) {
return (PI(pow(r,2))) * h; }

OriginalL'auteur Bowlslaw | 2011-04-01