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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)