[英]“Expected function body after function declarator ” compiled using GCC in Terminal
[英]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_ttc
與prix_ht+2.6
進行比較,但未分配該值。 您應該只使用一個=
:
prix_ttc=(prix_ht)+(2.6);
只需將{放在int main()之后,並在行號{上刪除{ 五
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.