| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 676 人关注过本帖
标题:猜数字程序问题
取消只看楼主 加入收藏
suckdog
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2007-9-19
结帖率:41.67%
收藏
 问题点数:0 回复次数:0 
猜数字程序问题
我给电脑输入一个答案, 然后让玩家才我输入的数字, 如果他猜高了我会提示他, 猜低了也提示, 但是如果猜超过8次的话, 程序就自动显出答案, 如果按0的话就退出。

我现在的程序其他的都没问题,除了玩家猜了8次后,程序还是不显答案, 还让玩家继续无限猜下去, 不知道问题出在哪里了, 大家帮忙看一下,谢谢啦

#include <iostream>
using namespace std;

int main ()
{
    const int num=56;
    int guess, i, flag=0, count=1;
   
    cout<<"Secret number between 1-100 generated..."<<endl;
   
    do
    {
        cout<<"Please enter your guess?";
        cin>>guess;
        
        if (guess<num && guess!=0)
        {
           if(num-guess<=5)
              cout<<guess<<" is lower than the answer but close..."<<endl;
           else
              cout<<guess<<" is lower than the answer..."<<endl;
        }
        
        else if (guess>num)
        {
           if(guess-num<=5)
              cout<<guess<<" is greater than the answer but close..."<<endl;
           else
              cout<<guess<<" is greater than the answer..."<<endl;
        }
        
        else if (guess==0 || count>8)
             flag=1;
        
        else
        {
            cout<<"Correct in "<<count<<" guesses."<<endl;
            flag=1;
        }
        count++;
    }while (flag != 1);
   
    if(count>8)
       cout<<"8 guesses. The secret number is "<<num<<"."<<endl;
    else if (guess==0)
       cout<<count<<" guesses. The secret number is "<<num<<"."<<endl;
   
    return 0;
}
搜索更多相关主题的帖子: 数字 
2010-04-08 11:56
快速回复:猜数字程序问题
数据加载中...
 
   



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

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