获取最近的时间而不是最长时间

时间:2017-09-16 17:54:21

标签: c

我需要maxhrmaxmin才能记录最长时间。在我的if((hr>maxhr)||((hr==maxhr)&&(min>maxmin)));下面是我存储我的int的地方,但它会在最近输入的时间内返回。我理解问题但不知道如何修复它。

另外,在if语句中,我试图说当前hr是否大于我的最大OR如果我的小时数相等但我的当前min大于我的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);
}

1 个答案:

答案 0 :(得分:2)

上述声明if((hr>maxhr)||((hr==maxhr)&&(min>maxmin)))最后有一个分号。这可能是你的问题吗? if语句看起来是正确的。