标题:不知道问题出在哪了?
只看楼主
vcfeng
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-4-16
结帖率:0
已结贴  问题点数:20 回复次数:1 
不知道问题出在哪了?
新手入门看的是 c Primer Plus
在书中有个例题我编译了运行是这个样子不知道是怎么回事
#include<stdio.h>
const int S_PER_M=60;
const int S_PER_H=3600;
const double M_PER_K=0.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 kilometers,the distance run.\n");
    scanf("%1f",&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);
    return 0;
}
然后输入10.0 36 23结果是这个样子的不知道是什么回事
搜索更多相关主题的帖子: running converts double include average 
2015-04-16 16:59
我爱吃青菜
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:6
帖 子:190
专家分:500
注 册:2015-3-29
得分:20 
请注意第17行,scanf("%1f",&distk);
"%1f"是什么,阿拉伯数字1!!!应该是%lf(字母l,L)
改过了就好了
2015-04-16 21:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444093-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.208927 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved