2017-09-16 4 views
0

maxhrmaxminが必要です。私のif((hr>maxhr)||((hr==maxhr)&&(min>maxmin)));の下には私のintが格納されていますが、入力された直近の時刻が返されます。問題は理解していますが、それを修正する方法はわかりません。最大時間の代わりに最近時刻を取得する

また、if文では、現在のhrが最大値よりも大きいか、両方の時間が等しい場合でも現在の最小値がmaxminより大きいかどうかを判断しようとしています。私はこれを正しく表現していますか?

#include <stdio.h> 
void main() 
{ 
    int hr; 
    int min; 
    int dives; 
    int counter=0; 
    int maxmin=0; 
    int maxhr=0; 
    int totmin=0; 
    int tothr=0; 
    printf("Please enter all dive times, one by one, with hours first and   minutes second, separated by a colon. Ex HH:MM\n"); 
    dives = scanf("%d:%d", &hr,&min); 

    while(dives != EOF) 
    { 
     counter++; 
     tothr = tothr+hr; 
     totmin = totmin+min; 
     if(totmin>59) 
     { 
      totmin = totmin-60; 
      tothr = tothr+1; 
     } 
     if((hr>maxhr)||((hr==maxhr)&&(min>maxmin))); 
     { 
      maxhr = hr; 
      maxmin = min; 
     } 
     dives = scanf("%d:%d", &hr,&min); 
    } 
    printf("The longest dive is %d:%d\n",maxhr,maxmin); 
    printf("The total dive time is %d:%d\n",tothr,totmin); 
} 
+0

あなたは本当に 'scanf'の後ろに' while'を隠すべきではありません。 'scanf'が返すものを確認する必要があります。 – mch

+2

時間と分を合計分に変換するだけの理由はありますか? – EOF

+0

私は合計分を計算することを検討していますが、私のコントロールdは以前と同じようにプログラムを終了していません。また、maxhr = hrはhrの値をmaxhrに保存しているか、単にhrの値をmaxhrと共有しているだけです。単純に共有している場合、hrの新しい値を入力するたびにmaxhrが変更されないためです。 –

答えて

2

上記の文if((hr>maxhr)||((hr==maxhr)&&(min>maxmin)))の最後にセミコロンがあります。それはあなたの問題だろうか? if文は正しいと思われます。

+0

";"を削除しました。しかし今、私のコントロールdはもはや何もしていません。思考? –

+0

「思考? ---今度はそれをデバッグしてください。 – zerkms

関連する問題