我正在尝试编写一个小程序来计算价格和费用。
有两条错误消息:
7 : "Expected function body after function declarator"
9 : Expected identifier or "("
代码是:
#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;
不是 C 代码,您可以这样声明变量:
float prix_ht, prix_ttc;
您应该在 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;
}
另请注意,我修复了您的最后一个 printf
行,您将指针传递给
float
。
你应该检查scanf
的返回值,你不知道它是否能够
读取float
并转换它。你应该这样做
if(scanf("%f", &prix_ht) != 1)
{
fprintf(stderr, "Could not read float for prix_ht\n");
return 1;
}
双==
用于比较
prix_ttc==(prix_ht)+(2.6);
将值 prix_ttc
与 prix_ht+2.6
进行比较,但并未对其进行赋值。你
应该只使用一个 =
:
prix_ttc=(prix_ht)+(2.6);
关于c - 函数声明符代码块之后的预期函数体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48955182/