2016-12-01 21 views
-1

次のコードがありますが、センチネル番号を1回入力した後に壊れてしまいますが、その時点でセンチネル番号を2回入力する必要があります。何か案は?cのセンチネルループ実行

#include <stdio.h>// Include a standard C Library 
#define Sentinel_Numb -1 
int main(){ 

    int ID[360];    
    float seconds[360]; 
    int i = 0; 

printf("please enter the ID and how many seconds to calculate enter -1 when done\n"); 

while (1)       
{ 
    scanf_s("%d",&ID[i]); 
    scanf_s("%f",&seconds[i]); 

    if(ID[i] == Sentinel_Numb || seconds[i] == Sentinel_Numb){ 
     break; 
     } 
    i++; 
} 

return 0; 
} 
+0

? – yano

+0

コンパイルされません。 "i"は定義されていません。 – TonyB

+0

申し訳ありませんが、私は – drez

答えて

1

に変更します。私はi`が定義され、どこかに初期化されると仮定し、 `

scanf_s("%d",&ID[i]); 
if (ID[i] == Sentinel_Numb) 
    break; 
scanf_s("%f",&seconds[i]); 
if (seconds[i] == Sentinel_Numb) 
    break; 
0
while (1)       
{ 
    scanf_s("%d",&ID[i]); 

    if (ID[i] == Sentinel_Numb) 
     break; 

    scanf_s("%f", &seconds[i]); 

    if (seconds[i] == Sentinel_Numb) 
     break; 
    i++; 
} 
関連する問題