2015-02-11 105 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之后

相关问题