#include <stdio.h>
int main(void)
{
int days, hours, mins;
float a, b, c, total, temp, tempA, tempB;
a = 3.56;
b = 12.50;
c = 9.23;
total = a+b+c;
days = total/24;
temp = total/24 - days;
hours = temp * 24;
tempA = temp*24 - hours;
mins = tempA*60;
while (hours >= 24)
{
hours= hours-24;
days +=1;
}
while (mins >= 60)
{
mins=mins-60;
hours +=1;
}
printf("days:%d\n", days);
printf("hours:%d\n", hours);
printf("mins:%d\n", mins);
return 0;
}
我想小數小時轉化爲真正的時間,我可以做到這一點很好,但我想增加天時間,如果時間超過24分鐘,如果超過60分鐘。 while循環會減去它並打印出新的值,但小時/天不會變得複雜。 這是1天1小時77分 我想它讀1天2小時17分 但我1天1小時17分鐘。複合/ while循環
您可能需要手動檢查你的數學; '3.56 + 12.5 + 9.23 == 25.29',比一天多1.29分鐘。 – sarnold 2011-02-28 02:42:03
嗯是啊我認爲我做了我的數學錯誤 – 2011-02-28 02:47:45
爲什麼你要避免一個mod運算符'%'的任何特定原因?你的實現會變得更加簡單。 – bits 2011-02-28 02:57:51