2016-11-04 13 views
0

入力を終了するタイミングを選択して「int finish」を初期化します。しかし、ループはそれをバイパスします。 私はdo-while文、しばらく試してみましたが、あなたの意図は、彼らが終了していることを示していない限り、8回までループを実行する場合、それは私のために私のループは終了しません

char snails[8][11]; 

int count; 
int finish; 
do 
{ 
    for (count = 0; count < 8; count++) 
    { 
     printf("Enter the snail's name:"); 
     scanf("%10s", &snails[count]); 
     int timea; 
     int timeb; 
     int timec; 
     int timed; 

     printf("Enter %s 's time for the first leg:", snails[count]); 
     scanf("%d", &timea); 
     printf("Enter %s 's time for the second leg:", snails[count]); 
     scanf("%d", &timeb); 

     printf("Enter %s 's time for the third leg:", snails[count]); 
     scanf("%d", &timec); 
     printf("Enter %s 's time for the fourth leg:", snails[count]); 
     scanf("%d", &timed); 

     int timef = timea + timeb + timec + timed; 

     int time1 = timef/60; 
     int time2 = timef % 60; 

     printf("%s finished in %d minutes and %d seconds \n", snails[count], time1, time2); 
     printf("Type 1 if you have finished inputting or 0 if you have not:"); 
     scanf("%d", &finish); 
    } 


} while (finish == 0); 


return 0; 

}

+1

Nitpick: 'scanf("%10s "、&snails [count]);'はscanf( "%10s"、snails [count]); – haccks

+0

'do'-' while'ループが終了するまで条件をチェックしないためです。あなたの 'for'ループの条件として' count <8 && finish!= 0'を試し、 'do'-' while'を削除してください。 –

+0

私は&& finish == 0を "count <8"に追加してくれてありがとう –

答えて

0

をそれをしていません。

1. do whileループを削除します。次の

2.Do 1:

count < 8 && finish != 1 

またはループのためのブレイク::への一見のための条件を変更する

if (finish == 1) break; 

それがループのために実行されます

  • それは8回です。
  • または完了したかどうか尋ねられたときに1と入力します。
関連する問題