2012-04-03 131 views
1

我是C編程新手,剛剛遇到此程序並出現問題。它說它在我表示的線上有錯誤。任何人都可以幫忙嗎?printf在編譯時顯示錯誤

#include <stdio.h> 
#include <stdlib.h> 
#include <conio.h> 
int main() 
{ 
    float a; 
    printf("Hello world!\n"); 
    scanf("%d",&a) 
    printf("you entered: %f",a);//here is the error 
    getch() 

} 

我正在使用CodeBlocks。

+1

只有一個評論:'conio.h'不是標準C庫的一部分。 'getch()'也不是:http://en.wikipedia.org/wiki/Conio.h你可能想考慮不使用這些EVER :) – ArjunShankar 2012-04-03 15:11:04

+0

下次,請發佈你得到的實際錯誤信息。 – 2012-04-03 15:29:05

回答

3

getch()之後缺少分號?和scanf()之後?

+0

和'scanf'也是如此。 – 2012-04-03 15:08:56

+0

非常感謝我得到它 – 2012-04-03 15:10:28

+0

@NishchalGautam每當你在某一行發現一個錯誤,在該行內及其周圍搜索錯誤 – 2012-04-03 15:11:23

0

缺少多個分號:

float a; 
printf("Hello world!\n"); 
scanf("%d",&a); <--- HERE 
printf("you entered: %f",a);//here is the error 
getch(); <--- AND HERE 
+1

它應該是'%f'(或相當於)for在'scanf'中浮動 – 2012-04-03 15:09:16

1

您在

scanf("%d",&a) 

getch() 
1

末丟失分號我看到兩個分號失蹤...

scanf行還需要建議編譯器指令正在結束,並且您可能會在下一行看到錯誤,因爲它認爲它仍在上一行。