| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 360 人关注过本帖
标题:求助——关于循环
收藏  订阅  推荐  打印 
ohr798546
Rank: 1
等级:新手上路
帖子:4
积分:154
注册:2008-6-16
求助——关于循环

这个程序的功能是用三角函数来求树的高度,内有一个英尺/英寸的转换式。
为了避免一闪而过,使用了do-while循环。
结果不起作用……
之前编过的程序都没有出现这种现象……
问题何在啊……

原代码:
//the hight of the tree
//17-06-08 14:30

#include <iostream>
#include <cmath>
#include <cctype>
using std::cout;
using std::cin;
using std::tan;
int main () {
    float d[3]={0};
    float h=0;
    float angle=0;
    float resault=0;
    const float ipf=12.00;
    char agian='n';
    do {
    cout <<"Enter the hight of Protractor.\nInches:";
    cin >>h;
    cout <<"\nEnter the angle on the Protractor.:\n";
    cin >>angle;
    cout <<"\nEnter the long between the tree and the Protractor.\n";
    cout <<"Feet,Inches:";
    cin >>d[0]>>d[1];
    d[2]=d[0]*ipf+d[1];
    resault=h+d[2]*tan(angle);
    cout <<"\nThe hight of the tree is:\n"<<resault<<" inches";
    cout <<"\nRetry(Y\\N)?";
    cin >>agian;
    } while (tolower(agian)=='y');
    return 0;
}

本人初学C++,编的都是一些练习小程序。
高手指教下哈……
搜索更多相关主题的帖子: float  三角函数  std  using  include  
2008-7-10 14:03
zhgxy28
Rank: 1
等级:新手上路
帖子:4
积分:156
注册:2008-4-22

出来的结果不符合要求,
问题出在:
resault=h+d[2]*tan(angle)的tan(angle)其算出的值是错的,
应在前定义:
#define PI 3.1415926
该句改为:
resault=h+d[2]*tan((angle/180)*PI)
就可以了。
2008-7-10 15:44
ohr798546
Rank: 1
等级:新手上路
帖子:4
积分:154
注册:2008-6-16

意思就是说在tan()中应使用弧度值?
了解&谢谢
2008-7-10 15:51
水中无月
Rank: 2
等级:注册会员
帖子:186
积分:1992
注册:2008-6-17

用getch()函数能防止程序“一闪而过”

十里平湖霜满天,寸寸青丝愁华年,对月形单望相互,只羡鸳鸯不羡仙.
2008-7-11 17:11
我是杨过
Rank: 2
等级:注册会员
帖子:49
积分:620
注册:2007-11-23

你是在VC中编的吗,如果不是建议,包含conio.h,然后用getch()

不要幻想,因为那从来不会是真的!
2008-7-12 21:25
ohr798546
Rank: 1
等级:新手上路
帖子:4
积分:154
注册:2008-6-16

我用的编译器是Dev-C++
至于循环吗……
总不会只输入一轮就算了……
还能多试几下编译成功的那种感觉
嘎嘎……
2008-7-14 13:00
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.055084 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved