簡體   English   中英

函數聲明符代碼塊之后的預期函數體

[英]expected function body after function declarator codeblocks

我正在嘗試編寫一個小程序,該程序會計算收費價格。

有兩個錯誤消息:

7:“函數聲明符后的預期函數主體”

9:期望的標識符或“(”

代碼是:

#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_ttcprix_ht+2.6進行比較,但未分配該值。 您應該只使用一個=

    prix_ttc=(prix_ht)+(2.6);

只需將{放在int main()之后,並在行號{上刪除{

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM