2015-02-11 106 views
-5

我是編程新手,這就是我在嘗試編譯此程序時所得到的結果。你能幫忙嗎?預期';'在'{'令牌之前10

#include<stdio.h> 
int main() 

{ 

    int Fahrenheit; 

    int Celcius; 

    int choice; 

    int temperature; 

    printf ("What do you want to do? (1/2) \n 1. Fahrenheit to Celcius \n. 2. Celcius to Fahrenheit \n. " 

    if (1) 

{ 

    printf ("Enter Fahrenheit \n.") 

    scanf ("%d", &Fahrenheit); 

    Celcius=(Fahrenheit-32)*5/9; 

    print("The temperature in Celcius is %d \n", Celcius); 

} 

    else (2) 

{ 

    printf ("Enter celcius\n"); 

    scanf ("%d", &Celcius); 

    Fahrenheit=Celcius*((9/5)+32); 

    printf ("The temperature in Fahrenheit is %d \n, Fahrenheit); 

    } 

    } 
+2

你在幾個地方丟失了''''和';'。 – juanchopanza 2015-02-11 19:46:18

+5

'如果(1)'不符合你的想法。 – njzk2 2015-02-11 19:46:37

+1

而'else(2)'也不是。 – 2015-02-11 19:47:08

回答

1

下面是我找到的所有編譯錯誤的列表。

的第一個問題是在這條線:

printf ("What do you want to do? (1/2) \n 1. Fahrenheit to Celcius \n. 2. Celcius to Fahrenheit \n. "

你缺少一個右括號和分號。

另一個是在這裏:

printf ("Enter Fahrenheit \n.")

你到底錯過了一個分號。

的另一個問題是在這一行:

else (2)

else沒有像if()一個條件塊,所以(2)就像是需要在情況下,在if執行條件語句的處理else屬於不滿意。但是,它錯過了';'最後,因此錯誤。 { }所包含的塊與您的else完全無關。

下面是另一個:

printf ("The temperature in Fahrenheit is %d \n, Fahrenheit);你錯過了你的字符串字面關閉"

通常,即使你糾正了所有這些錯誤,你的代碼仍然不會達到你期望的效果。我建議你在嘗試編碼之前先寫一本好書或初學者的編程教程。

+0

謝謝。我正在破壞我的大腦一段時間。 – Tafadzwa 2015-02-11 20:02:53

0

通常,預期的';'錯誤意味着你錯過了一個分號。 如果您查看第10行,則在if(1)之後和打印語句之後缺少分號。

0

else之後不應該是(2)。否則沒有附加條件,並且只是if的可選部分

0

你需要;在第10行的printf之後

相關問題