逻辑错误 指点下

kukuyouhuo 2008-04-09 04:58:00
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>
#include<ctime>
#include<string>
int display();

int main()
{int a,b;
int x;
srand(time(0));
cout<<"i have a number between 1 and 1000"<<endl;
cout<<"can you guess my number?"<<endl;
cout<<"please type your first guess:";

while(a=display())
{cin>>b;

if(b==a)
{ cout<<"Excellent!you guess the number"<<endl;
cout<<"would you like to play again(y or n)?";
cin>>x;
if(x==1)
continue;
else
break;}

while(b!=a)
{if(b>a)
{cout<<"too high try again:";
cin>>b;}
if(b<a)
{cout<<"too low try again:";
cin>>b;}
}

}
system("pause");
return 0;
}
int display()
{ return 1+rand()%999;}


这个语句块实现不了 大家帮忙改进下 谢谢


...全文
77 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
oo 2008-04-09
  • 打赏
  • 举报
回复
换一下位置就可以了

while(a=display()) 
{cin>>b;
while(b!=a)
{if(b>a)
{cout < <"too high try again:";
cin>>b;}
if(b <a)
{cout < <"too low try again:";
cin>>b;}
}

cout < <"Excellent!you guess the number" < <endl;
cout < <"would you like to play again(y or n)?";
cin>>x;
if(x==1)
continue;
else
break;



}

64,849

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧