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 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题