我需要maxhr
和maxmin
来只记录最高时间。在我的 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/