2014-01-12 54 views
0

對不起,但我需要一雙新的眼睛。語法else if in C

case '2': 
    printf("\n>>> Desligar equipamento <<<"); 
    do { 
     printf("\nNumero? ");scanf("%d",&nr); 
    } 
    while (nr<1 || nr>99); 

    if (retirar(nr, f_equipamento_uso, f_categoria)){ 
     registarHora(n, 0, equipamento, data); //moved from the else 
     unblanker(nr, f_equipamento_uso, f_categoria);    
     //Imprimir Eq Disponiveis para verificar função abaixo 
     printf("\nRemover dos Equipamentos Disponiveis? S/N"); 
     scanf("%c", &sn); 
     getch(); 

     if (sn == 'S' || sn == 's') { 
      printf("should remove from dsp"); 
      getch(); 
      //retirar(nr, f_equipamento_disp, f_categoria); 
     } 
     else { 
     //This is the **bold else** 
     } 
    else { 
     printf("Equipamento nao existe."); 
     getch();  
    }     
    } 
    break; 

我有兩個,如果elses那裏。 刪除粗體else我可以編譯,但不能像前面的if那樣「隱藏」。 如果我不刪除,我有語法錯誤

+3

你錯過了在大括號'} '爲外部'if'。 –

+1

你只是錯誤''' – qrdl

+0

哦,對,我有它在結束後,而不是有問題的其他。 – Pedro

回答

2

你應該之前

else { 
     printf("Equipamento nao existe."); 
     getch();  
    } 

插入}那麼你的代碼看起來是這樣的結構:

case constant-expression: 

do 
{ 
} while(expression); 

if (expression) 
{ 

    if (expression) 
    { 
    } 
    else 
    { 
    } 

} 
else 
{ 
} 

} 

break;