c - 获取最近时间而不是最长时间

标签 c

我需要maxhrmaxmin 来只记录最高时间。在我的 if((hr>maxhr)||((hr==maxhr)&&(min>maxmin))); 下面是我存储 int 的地方,但它不断返回最近输入的时间in. 我明白这个问题,但不知道如何解决。

此外,在该 if 语句中,我试图说明当前小时是否大于我的最大值,或者我的两个小时是否相等但我当前的最小值是否大于我的最大值。我表达正确吗?

#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);
}

最佳答案

提到的语句 if((hr>maxhr)||((hr==maxhr)&&(min>maxmin))) 末尾有一个分号。那会是你的问题吗? if 语句看起来是正确的。

关于c - 获取最近时间而不是最长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46256852/

相关文章:

c - 为什么我的引脚中断在整个过程中只工作一次?

无法使用 mmap/malloc/open 等在 64 位 linux 系统上创建大于 2GB 的文件

c - 如何一次读取 3 个字符的文本文件?

c - 打印整数数组时输出不正确

c - 我正在尝试按分数对节点进行排序。我不知道我有什么错误

c - 不允许使用不完整类型,2 个结构

调用 scanf 后代码崩溃

sqlite3,通过索引检索行元素的最佳方法?

c++ - 在 GPRS 连接处于事件状态时发送/接收 SMS

c# - 将 OpenSsl SSL_ctrl 函数编码到 C#