例题求指点,该如何处理
例题求指点
书上的一个例题,我自己写了一下不知道错在哪,请各位高手指点,谢谢!
------解决方案--------------------
const S_PER_M = 60;
const S_PER_H = 3600;
改成:
const int S_PER_M = 60;
const int S_PER_H = 3600;
就OK了
书上的一个例题,我自己写了一下不知道错在哪,请各位高手指点,谢谢!
- C/C++ code
#include <stdio.h> const S_PER_M = 60; const S_PER_H = 3600; int main(void) { double km; //公里数 double rate; //公里每小时 int min,sec; //用时。分钟、秒 int times; //用秒计算的时间 double stime; //公里每秒 int mmin,msec; //一公里的时间,分钟和秒 printf("请问你每天能跑都少公里?\n"); scanf("%lf",&km); printf("请问跑完这段距离您需要多少分钟?\n"); scanf("%d",&min); printf("和多少秒呢?\n"); scanf("%d",&sec); times = min * S_PER_M + sec; rate = km / (times / S_PER_H); stime = (double) times / km; mmin = (int) stime / S_PER_M; msec = (int) stime % S_PER_M; printf("您每天要跑 %1.2f 公里,所需时间是 %d 分钟 %d 秒。\n",km,min,sec); printf("您跑完一公里需要 %d 分钟",mmin); printf(" %d 秒。\n您的平均速度是 %1.2f 公里/小时。\n",msec,rate); return 0; }
------解决方案--------------------
const S_PER_M = 60;
const S_PER_H = 3600;
改成:
const int S_PER_M = 60;
const int S_PER_H = 3600;
就OK了