」調用對象類型'int'的類型不是函數或函數指針「錯誤出現在第26行。這是我的公式 我不能確定錯誤的根源,請大家幫忙26行錯誤「被調用的對象類型」int「不是函數或函數指針嗎?爲什麼會出現這種情況?
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <math.h>
14
15 int main()
16 double p1, ac, at, p2, p3, ar, p;
17 int code;
18 p=(p1+p2+p3)/2;
19 setvbuf(stdout, NULL, _IONBF, 0);
20
21 while(1){
22 printf("Enter code and parameter(s) (Code=0 to Quit):");
23 scanf("%d%lf%lf%lf", &code, &p1, &p2, &p3);
24 if(code==0) break;
25 if(code==1){
26 ac=2*M_PI*(p1*p1);
27 printf("area of circle: %f", ac);
28 }
29 else if(code==2){
30 at=sqrt(p*(p-p1)*(p-p2)*(p-p3));
31 printf("area of triangle: %f", at);
32 }
33 else if(code==3){
34 ar=p1*p2;
35 printf("area of rectangle: %f", ar);
36 }
37 return EXIT_SUCCESS;
38 }
39 }
順便說一句,爲什麼不使用'switch(code)'而不是級聯的'if'? – DyZ
一個合適的C庫不在''中定義'M_PI'。對於調試,嘗試'ac = 2 * 3.14 *(p1 * p1);' –
chux
@chux非常正確,但是符合XSI的math.h *將*定義'M_PI',如果您有'#define _XOPEN_SOURCE 700'任何系統頭包括。可能這個程序沒有。 – rici