2013-04-27 76 views
-1

任何幫助將是巨大的!收到錯誤「預期標識符或‘(’前‘{’令牌用C

#include <stdio.h> 
#define pi 3.14159 



int main() 
{ 
    float r; 
    char PI; 

/*Program for circumference. */ 

    printf(" This is a program that will calculate circumference.\n"); 
    printf("Please put in your radius.\n"); 

    scanf("%f", &r); 
    printf("Please input PI\n"); 
    PI = getchar(); 
} 

    { 
    if {(char != PI || 3.14); 
    printf("Incorect value\n"); 
} 

    else { 
    printf("Thank you, the circumference is now.\n"); 
    printf("%f", (r) * pi *2); 
} 


return 0; 

} 

我試圖找出這個錯誤,我肯定,四處搜尋,但真的沒什麼彈起我的具體問題,如果有幫助,這是正確的「if」語句開始之前,也許我可以用一個太多的「{」?

+2

主要在'PI = getchar函數被終止();從那時起,每個支架都是錯誤的。 – 2013-04-27 21:40:25

+0

謝謝!欣賞它,我應該稍後使用它嗎?你認爲可能是scanf(「PI \ n」);更有意義?既然是用戶輸入? – 2013-04-27 21:42:19

+0

@MarkusAndrewWhite如果你使用'的scanf()',它應該是'的scanf( 「%C」,與PI)''不scanf的( 「PI \ n」)' – 2013-04-27 21:56:15

回答

1

我已經指出了它comments.Make使用帽習慣的錯誤爲#define宏,不是爲了variables.And最後,您if的條件應該是if(PI!=pi)卸下襬臂的{之間和(,並且還之後;)

#include <stdio.h> 
#define pi 3.14159 



int main() 
{ 
    float r; 
    char PI; 

/*Program for circumference. */ 

    printf(" This is a program that will calculate circumference.\n"); 
    printf("Please put in your radius.\n"); 

    scanf("%f", &r); 
    printf("Please input PI\n"); 
    PI = getchar(); 
} //This is the source of error as `main()` ends after this `}' 

    { 
    if(PI!=pi) //You have used a `;` after if's condition & an extra '{' before it 
    printf("Incorect value\n"); 
} 

    else { 
    printf("Thank you, the circumference is now.\n"); 
    printf("%f", (r) * pi *2); 
} 


return 0; 

} 
+0

@MarkusAndrewWhite恐怕有你code.Let進一步的錯誤我檢查again.wait ... – 2013-04-27 22:07:30

+0

@MarkusAndrewWhite嘿馬庫斯,這裏是正確的程序http://ideone.com/WFGyQA我沒有在這裏編輯爲否則指出不正確的行和語法會很困難。 – 2013-04-27 22:15:15

+0

@MarkusAndrewWhite在你的程序有很多東西是redundant.Further,它是棘手的期望pi'進入了'值和值'#define''d匹配爲'pi'是不是一個精確的number.Since你對C來說看起來很新,鑑於你對scanf()的理解,讓我們不要偏離你提出的主要問題。如果你有進一步的疑問,歡迎發表進一步的問題。 – 2013-04-27 22:17:30

1

您在第一}終止您的主要功能你有一個不平衡的開放和關閉大括號的匹配,這是造成這個問題,你也有一個與你的if聲明有關的問題

if {(char != PI || 3.14); 

應爲

if (char != PI || 3.14) 

或者更具體地說是整個的if-else應該

if (char != PI || 3.14) 
{ 
    printf("Incorect value\n"); 
} else { 
    printf("Thank you, the circumference is now.\n"); 
    printf("%f", (r) * pi *2); 
} 
+0

謝謝!我很感激! – 2013-04-27 21:47:37

+0

這解決了我的其他錯誤,現在我在'char'之前得到預期的表達式。任何輸入。 – 2013-04-27 21:54:36

+0

@ mathematician1975確定'如果(字符!= PI || 3.14)'是正確的C語法?這是什麼意思?我只是不明白,人怎麼能聲明',如果內部的一些笨拙的表達'char'類型''的條件! – 2013-04-27 22:22:02

相關問題