| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1376 人关注过本帖
标题:新手学C++的一些疑问
取消只看楼主 加入收藏
峻峰
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-11-18
收藏
 问题点数:0 回复次数:2 
新手学C++的一些疑问
请各位帮我看一下我的代码有什么问题。。
运行之后,结果总是出现不是期待种的结果

//build a program to know how many seconds in a year
//in this program ,you should key in year day hour and minute
#include <iostream>
using namespace std;
int main()
{
    int year,day,hour,minute,second;
    int seconds;
    int stop;//use the key in function to stop the exe
        cout<<"key in the years you want to know\n";
            cin>>year;
         cout<<"key in the days in a year\n";
            cin>>day;
        cout<<"key in the hours in a day\n";
             cin>>hour;
        cout<<"key in the minutes in an hour\n";
            cin>>hour;
        cout<<"key in the seconds in a minute\n";
            cin>>second;
        seconds=year * day * hour * minute *second;
        cout<<"the years you key in is "<<year<<" ,and the seconds number is \n"<<seconds<<endl;
cin >>stop;
}
搜索更多相关主题的帖子: 疑问 
2008-12-04 20:12
峻峰
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-11-18
收藏
得分:0 
貌似问题还没解决嘛。。
这个设置,我用来检验一下运算的
没想到一算就出问题了
我自己输入数据的适合,感觉没什么问题
而且我是用计算器算过的。

但是在这里却出现问题了

或不会是数字的二进制数目到达顶峰啊。。。我记得有这样的错误存在。
但是一直都没有解决过
2008-12-05 18:11
峻峰
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-11-18
收藏
得分:0 
哎呀,我真是大蒙。。。居然打字的适合打成一样了。。。

其实问题还是有的。

例如,我在程序上编辑一个数的平方。。。当这个数大于100000的适合,会出现乱码。。。但是在99999的适合还是可以。。。也就是说100000的平方,就是乱码了。。不是期待结果。
就像是这样。。。
#include <iostream>
using namespace std;
int sqr(int a);
int main()
{
    int stop;//用来停止,方便观察结果
    int num;
    cin>>num;
    cout<<sqr(num);
    
    cin >>stop;
return 0;
}
int sqr(int a )
{
    return a *a;
}

当输入数字大于100000的时候,就产生错误的东西了。

[[it] 本帖最后由 峻峰 于 2008-12-6 18:58 编辑 [/it]]
2008-12-06 18:50
快速回复:新手学C++的一些疑问
数据加载中...
 
   



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

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