| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:我的程序怎么了?
只看楼主 加入收藏
DoubleFly
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-2-8
收藏
 问题点数:0 回复次数:2 
我的程序怎么了?

#include <iostream>
int main()
{
using namespace std;
unsigned short small;
unsigned long large;
unsigned long skip;
unsigned long target;
const unsigned short MAXSMALL=65536;
cout<<"enter a smll number:";
cin>>small;
cout<<"enter a large number:";
cin>>large;
cout<<"enter a skip number:";
cin>>skip;
cout<<"enter a target number:";
cin>>target;
cout<<"\n";
while (small<large && large>0 && small<MAXSMALL)
{
small++;
if (small%skip==0)
{
cout<<"skipping on"<<small<<endl;
continue;
}
if (large==target)
{
cout<<"target reached!";
break;
}
large-=2;
}
cout<<"\nsmall:"<<small<<"large:"<<large<<endl;
return 0;
}

我输入了2 ,20 ,4 ,6这四个数字,按道理说应该显示
Skipping on 4
Skipping on 8
Small 10 large 8
为什么我的输出是small:2 large:20
为什么我前面的条件语句没起作用?

搜索更多相关主题的帖子: include number target 
2007-02-08 16:21
slowlybear
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-10-18
收藏
得分:0 
第9行:
const unsigned short MAXSMALL=65536;

你用了short,这个是不支持到65536的,去掉以后程序结果正确.

2007-02-08 19:59
plusone
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-8-7
收藏
得分:0 

我帮你改了下.
#include <iostream.h>
#define MAXSMALL 65536

int main()
{
//using namespace std;
unsigned short small;
unsigned long large;
unsigned long skip;
unsigned long target;
//const unsigned short MAXSMALL=65536;
cout<<"enter a smll number:";
cin>>small;
cout<<"enter a large number:";
cin>>large;
cout<<"enter a skip number:";
cin>>skip;
cout<<"enter a target number:";
cin>>target;
cout<<"\n";
while (small<large && large>0 && small<MAXSMALL)
{
small++;
if (small%skip==0)
{
cout<<"skipping on"<<small<<endl;
continue;
}
if (large==target)
{
cout<<"target reached!";
break;
}
large-=2;
}
cout<<"\nsmall:"<<small<<"large:"<<large<<endl;
return 0;
}


2007-02-08 20:04
快速回复:我的程序怎么了?
数据加载中...
 
   



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

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