2012-04-03 102 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行还需要建议编译器指令正在结束,并且您可能会在下一行看到错误,因为它认为它仍在上一行。