2016-05-14 79 views
-2

HELPPPPPP ......這是我的用戶輸入溫度讀數的代碼,但我真的不知道我的代碼有什麼問題。當我編譯它說「預期表達之前,其他'」。我需要幫助,提前致謝。溫度讀數

#include <stdio.h> 

    main() 
    { 
    double lowest = 38; 
    double temp; 
    char bpower; 

    printf("Enter temperature(C):"); 
    scanf("%lf", &temp); 

    if(temp<lowest) 
    { 

    lowest = temp; 

    } 

    printf("Backup power on? (Y/N):"); 
    fflush(stdin); 
    scanf("%c", &bpower); 

    if(temp < 50); 
    { 

    printf("Normal mode of operation\n"); 
    printf("Continue to read the next temperature\n"); 

    } 

    else 

    { 

     if(temp < 80) 

     { 
     printf("Turn on circulating fan\n"); 
     printf("Continue to read the next temperature\n"); 

     } 


     else 

     { 
     if(bpower == 'N') 



     { 
     printf("Turn off equipment\n"); 
     printf("Lowest temperature is %.2f", lowest); 

     } 

     else 

     { 

     printf("Continue to read the next temperature\n"); 

     } 

     } 



} 
} 
+0

'fflush(標準輸入);' - 這不確定的行爲 –

+0

'如果(溫度<50);' - 仔細看這裏。 –

+0

可以做整理代碼的縮進 - 你需要這麼多的空行 –

回答

2

在您的if聲明之一中有一個雜散分號。更改此:

if(temp < 50); 
{ 

printf("Normal mode of operation\n"); 
printf("Continue to read the next temperature\n"); 

} 

這樣:

if(temp < 50) 
{ 

printf("Normal mode of operation\n"); 
printf("Continue to read the next temperature\n"); 

}