| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:这个哪里有错误
只看楼主 加入收藏
pytao1991
Rank: 1
等 级:新手上路
帖 子:55
专家分:4
注 册:2015-8-26
结帖率:62.5%
收藏
 问题点数:0 回复次数:6 
这个哪里有错误
/* Program 2.17 Calculating the height of a tree */
#include <stdio.h>

int main(void)
{
    long shorty =0L;                 // Shorty's height in inches 矮子的英寸高度
    long lofty =0L;                  // Lofty's height in inches  高个子的英寸高度
    long feet =0L;
    long inches =0L;
    long shorty_to_lofty =0L;        // Distance from Shorty to Lofty in inches  矮子和高个子的英寸差距
    long lofty_to_tree =0L;          // Distance from Lofty to the tree in inches  高个子到树的英寸差距
    long tree_height =0L;            // Height of the tree in inches  树的高度英寸
    const long inches_per_foot =12L;

    // Get Lofty's height  高个子的身高
    printf("Enter Lofty's height to the top of his/her head, in whole feet: ");
    scanf("%Ld", &feet);
    printf("            ...and then inches: ");
    scanf("%Ld", &inches);
    lofty = feet*inches_per_foot + inches;

    // Get Shorty's height up to his/her eyes   //矮子的身高到他的眼睛距离
    printf("Enter Shorty's height up to his/her eyes, in whole feet: ");
    scanf("%Ld", &feet);
    printf("                               ... and then inches: ");
    scanf("%Ld", &inches);
    shorty = feet*inches_per_foot + inches;

    // Get the distance from Shorty to Lofty   //高个子和矮子的距离
    printf("Enter the distance between Shorty and Lofty, in whole feet: ");
    scanf("%Ld", &feet)"
    printf("                                          ... and then inches:");
    scanf("%Ld", &inches);
    shorty_to_lofty = feet*inches_per_foot + inches;

    // Get the distance from Lofty to the tree   //高个子到树的距离
    printf("Finally enter the distance from Lofty to the tree to the nearest foot: ");
    scanf("%Ld", &feet);
    Lofty_to_tree = feet*inches_per_foot;

    // Calculate the height of the tree in inches  //在英寸计算树的高度
    tree_height = shorty+(shorty_to_lofty + lofty_to_tree)*(lofty-shorty)/
                                                              shorty_to_lofty;

    // Display the result in feet and inches  //英尺和英寸的显示结果
    printf("The height of the tree is %Ld feet and %Ld inches.\n",
                                           tree_height/inches_per_foot,tree_height% inches_per_foot);

    return 0;
}


这个是教学书里的,比对了,没发现输入错误,但是我执行的时候就提示出错
图片是错误信息,麻烦老师指出
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: include 高个子 
2015-09-13 21:14
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
#include <stdio.h>

int main(void)
{
    long shorty =0L;                 // Shorty's height in inches 矮子的英寸高度
    long lofty =0L;                  // Lofty's height in inches  高个子的英寸高度
    long feet =0L;
    long inches =0L;
    long shorty_to_lofty =0L;        // Distance from Shorty to Lofty in inches  矮子和高个子的英寸差距
    long lofty_to_tree =0L;          // Distance from Lofty to the tree in inches  高个子到树的英寸差距
    long tree_height =0L;            // Height of the tree in inches  树的高度英寸
    const long inches_per_foot =12L;

    // Get Lofty's height  高个子的身高
    printf("Enter Lofty's height to the top of his/her head, in whole feet: ");
    scanf("%Ld", &feet);
    printf("            ...and then inches: ");
    scanf("%Ld", &inches);
    lofty = feet*inches_per_foot + inches;

    // Get Shorty's height up to his/her eyes   //矮子的身高到他的眼睛距离
    printf("Enter Shorty's height up to his/her eyes, in whole feet: ");
    scanf("%Ld", &feet);
    printf("                               ... and then inches: ");
    scanf("%Ld", &inches);
    shorty = feet*inches_per_foot + inches;

    // Get the distance from Shorty to Lofty   //高个子和矮子的距离
    printf("Enter the distance between Shorty and Lofty, in whole feet: ");
    scanf("%Ld", &feet)"                                                     //这就不说什么了
    printf("                                          ... and then inches:");
    scanf("%Ld", &inches);
    shorty_to_lofty = feet*inches_per_foot + inches;

    // Get the distance from Lofty to the tree   //高个子到树的距离
    printf("Finally enter the distance from Lofty to the tree to the nearest foot: ");
    scanf("%Ld", &feet);
    Lofty_to_tree = feet*inches_per_foot;变量名首字母小写上下一致!

    // Calculate the height of the tree in inches  //在英寸计算树的高度
    tree_height = shorty+(shorty_to_lofty + lofty_to_tree)*(lofty-shorty)/
                                                              shorty_to_lofty;

    // Display the result in feet and inches  //英尺和英寸的显示结果
    printf("The height of the tree is %Ld feet and %Ld inches.\n",
                                           tree_height/inches_per_foot,tree_height% inches_per_foot);

    return 0;
}
不知道你代码功能。。。。但是~唉,路还长!

剑栈风樯各苦辛,别时冰雪到时春
2015-09-13 21:58
pytao1991
Rank: 1
等 级:新手上路
帖 子:55
专家分:4
注 册:2015-8-26
收藏
得分:0 
回复 2楼 林月儿
非常感谢订正错误,我太粗心了。我将上面两处错误修改以后,第32行好想还有问题
2015-09-13 22:16
pytao1991
Rank: 1
等 级:新手上路
帖 子:55
专家分:4
注 册:2015-8-26
收藏
得分:0 
/* Program 2.18 Calculating the height of a tree */
#include <stdio.h>

int main(void)
{
    long shorty =0L;                 // Shorty's height in inches 矮子的英寸高度
    long lofty =0L;                  // Lofty's height in inches  高个子的英寸高度
    long feet =0L;
    long inches =0L;
    long shorty_to_lofty =0L;        // Distance from Shorty to Lofty in inches  矮子和高个子的英寸差距
    long lofty_to_tree =0L;          // Distance from Lofty to the tree in inches  高个子到树的英寸差距
    long tree_height =0L;            // Height of the tree in inches  树的高度英寸
    const long inches_per_foot =12L;

    // Get Lofty's height  高个子的身高
    printf("Enter Lofty's height to the top of his/her head, in whole feet: ");
    scanf("%ld", &feet);
    printf("                                            ...and then inches: ");
    scanf("%ld", &inches);
    lofty = feet*inches_per_foot + inches;

    // Get Shorty's height up to his/her eyes   //矮子的身高到他的眼睛距离
    printf("Enter Shorty's height up to his/her eyes, in whole feet: ");
    scanf("%ld", &feet);
    printf("                                    ... and then inches: ");
    scanf("%ld", &inches);
    shorty = feet*inches_per_foot + inches;

    // Get the distance from Shorty to Lofty   //高个子和矮子的距离
    printf("Enter the distance between Shorty and Lofty, in whole feet: ");
    scanf("%ld",&feet);
    printf("                                       ... and then inches: ");//这一行怎么不对了,编译还是不执行
    scanf("%ld", &inches);
    shorty_to_lofty = feet*inches_per_foot + inches;

    // Get the distance from Lofty to the tree   //高个子到树的距离
    printf("Finally enter the distance from Lofty to the tree to the nearest foot: ");
    scanf("%ld", &feet);
    lofty_to_tree = feet*inches_per_foot;

    // Calculate the height of the tree in inches  //在英寸计算树的高度
    tree_height = shorty+(shorty_to_lofty + lofty_to_tree)*(lofty-shorty)/
                                                              shorty_to_lofty;

    // Display the result in feet and inches  //英尺和英寸的显示结果
    printf("The height of the tree is %Ld feet and %Ld inches.\n",
                                           tree_height/inches_per_foot,tree_height% inches_per_foot);

    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册


[ 本帖最后由 pytao1991 于 2015-9-13 23:00 编辑 ]
2015-09-13 22:57
hjx1120
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:李掌柜
等 级:贵宾
威 望:41
帖 子:1314
专家分:6927
注 册:2008-1-3
收藏
得分:0 
第三十行 scanf("%ld",&feet);
的分号是中文符号
2015-09-13 23:14
pytao1991
Rank: 1
等 级:新手上路
帖 子:55
专家分:4
注 册:2015-8-26
收藏
得分:0 
回复 5楼 hjx1120
非常感谢,已经可以了。哈哈,我都快睡不着觉了。刚开始学习
2015-09-13 23:20
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
我还能说什么

剑栈风樯各苦辛,别时冰雪到时春
2015-09-14 07:03
快速回复:这个哪里有错误
数据加载中...
 
   



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

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