[英]expected function body after function declarator codeblocks
I am trying to code a little program which calculates the price with fees. 我正在尝试编写一个小程序,该程序会计算收费价格。
There is two error messages : 有两个错误消息:
7 : "Expected function body after function declarator" 7:“函数声明符后的预期函数主体”
9 : Expected identifier or "(" 9:期望的标识符或“(”
The code is : 代码是:
#include <stdio.h>
#include <stdlib.h>
int main()
var float : prix_ht,prix_ttc;
{
//La taxe vaut 2,6 euros
//Saisie du prix hors taxes
printf("Saisir le prix hors taxes");
scanf("%f",&prix_ht);
prix_ttc==(prix_ht)+(2.6);
printf("Le prix ttc est :%f",&prix_ttc);
return 0;
}
var float : prix_ht,prix_ttc;
is not C code, you declare variables like this: 不是C代码,您可以这样声明变量:
float prix_ht, prix_ttc;
And you should write this line inside your main
function: 您应该在main
函数中编写以下行:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float prix_ht, prix_ttc;
//La taxe vaut 2,6 euros
//Saisie du prix hors taxes
printf("Saisir le prix hors taxes");
scanf("%f",&prix_ht);
prix_ttc==(prix_ht)+(2.6);
printf("Le prix ttc est :%f", prix_ttc);
return 0;
}
Also note that I fixed your last printf
line, you were passing a pointer to float
. 还要注意,我固定了最后一条printf
行,您正在传递一个指向float
的指针。
And you should check the return value of scanf
, you don't know if it was able to read a float
and convert it. 并且您应该检查scanf
的返回值,您不知道它是否能够读取float
并将其转换。 You should do 你应该做
if(scanf("%f", &prix_ht) != 1)
{
fprintf(stderr, "Could not read float for prix_ht\n");
return 1;
}
And double ==
is for comparing 双==
用于比较
prix_ttc==(prix_ht)+(2.6);
compares the value prix_ttc
with prix_ht+2.6
, it is not assigning it. 将值prix_ttc
与prix_ht+2.6
进行比较,但未分配该值。 You should use only one =
: 您应该只使用一个=
:
prix_ttc=(prix_ht)+(2.6);
just put { after int main() and remove { on line no. 只需将{放在int main()之后,并在行号{上删除{ 5 五
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.