humanint 2016-11-03 04:18 采纳率: 100%
浏览 1160
已采纳

c primer plus 第六版第5章程序清单5.16的问题

我使用visual studio2015 community编写了c primer plus 第六版第5章程序清单5.16。
#include
const int S_PER_M = 60;
const int S_PER_H = 3600;
const double M_PER_K = 62137;
int main(void)
{
double distk, distm;
double rate;
int min, sec;
int time;
double mtime;
int mmin, msec;

printf("this program converts your time for a metric race\n");
printf("to a time for running a mile and to your average\n");
printf("speed in miles per hour.\n");
printf("please enter,in kiometers,the distance run.\n");
scanf("%lf", &distk);
printf("next enter the time in minutes and seconds.\n");
printf("begin by entering the minutes.\n");
scanf("%d", &min);
printf("now enter the seconds.\n");
scanf("%d", &sec);

time = S_PER_M*min + sec;
distm = M_PER_K*distk;
rate = distm / time*S_PER_H;
mtime = (double)time / distm;
mmin = (int)mtime / S_PER_M;
msec = (int)mtime % S_PER_M;

printf("you ran %1.2f km (%1.2f miles) in %d min,%d sec.\n",
    distk, distm, min, sec);
printf("that pace corresponds to running a mile in %d min,",
    mmin);
printf("%d sec.\nyour average speed was %1.2f mph.\n", msec,
        rate);
getchar();
getchar();
return 0;

}
然后调试
this program converts your time for a metric race
to a time for running a mile and to your average
speed in miles per hour.
please enter,in kiometers,the distance run.
10.0
next enter the time in minutes and seconds.
begin by entering the minutes.
36
now enter the seconds.
23
you ran 10.00 km (621370.00 miles) in 36 min,23 sec.
that pace corresponds to running a mile in 0 min,0 sec.
your average speed was 1024705.45 mph.
最后三行和书上的数据不不一样,
图片说明
distm,min,sec,mmin,msec,rate返回的数据都不对,程序检查了很多遍。

  • 写回答

3条回答 默认 最新

  • YXTS122 2016-11-03 08:19
    关注

    const double M_PER_K =0.62137;
    应该是这样吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器