好吧,夥計們,我對此有一段時間。目前,我正在研究C語言中的if語句(很明顯,編程介紹),我似乎無法得到if else語句正確的語法。我瀏覽過網頁,但沒有找到任何相關答案。我目前收到的錯誤是: | 47 | error:expected')'數字常量之前|麻煩,如果C語言中的陳述與計算相結合
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float p(float r, float v)
{
return (v*v)/(r);
}
int main()
{
float r, v, answer; //The user input and print for title of values
puts("Enter Voltage:");
scanf("%f", &r);
puts("Enter Resistance:");
scanf("%f", &v);
answer = p(v, r);
printf("Pd=%.9f\n", answer);
return 0;
scanf("%f", answer);
if (answer >= 0.25)
{
/* if condition is true then print the following */
printf("WARNING: Power Dissipation should not exceed 1/4 Watt\n");
}
else if ((answer) 0.25 < =<0.5 >)
{
printf("WARNING: Power Dissipation should not exceed 1/2 Watt\n");
}
scanf("%f", &answer);
if ((answer 0.5< & 1 >=< 1)
printf("WARNING: Power Dissipation should not exceed 1 Watt");
}
如果您有空餘時間,請幫忙。
這將有助於縮進代碼。 – hetepeperfan 2014-10-17 20:23:36
你的第二個和第三個'if'語法錯誤。請查看您的課程筆記。 (關於重讀:我甚至無法理解你想要測試的內容......) – usr2564301 2014-10-17 20:23:52
看起來你在你的主體中間有一個'return'。這可能是不對的。 – dohashi 2014-10-17 20:25:09