c - 函数声明符代码块之后的预期函数体

标签 c codeblocks

我正在尝试编写一个小程序来计算价格和费用。

有两条错误消息:

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;
}

enter image description here

最佳答案

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_ttcprix_ht+2.6 进行比较,但并未对其进行赋值。你 应该只使用一个 =:

    prix_ttc=(prix_ht)+(2.6);

关于c - 函数声明符代码块之后的预期函数体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48955182/

相关文章:

c - 从 c 读取函数过早返回 0

c - 未初始化为 0 时的有趣值

c++ - 请求 ' ' 中属于 non_clas 的成员 ' ' ... Vtable,链接器错误?

c++ - 在 C++ 中使用第三方库

c - 解析两个数字 - 高位数字和个位数字

c - 套接字编程 - 为什么我们不将 sin_family 转换为网络顺序?

c - 在Linux中使用fallocate()快速预分配大文件

c - 宏参数不会接受传递的参数(nvcc)

C++ 代码未在 Visual Studio 中运行

c++ - 项目中无法识别代码块文件