猜数字游戏

来源:互联网 发布:js 数组取值 编辑:程序博客网 时间:2024/06/06 15:36


# include<iostream>
# include<time.h>
using namespace std;
int main()
{
 int a,b;
 srand(time(NULL));
 a=1+(rand()%1000);
 cout<<"scanf a numeber which you guess1-1000"<<endl;
 cin>>b;
 while(b!=-1)
 {
 if(b==a)
 {
  cout<<"You guessed the number"<<endl;
  
 }
 while(b<a)
 {
  cout<<"小了"<<endl;
  cin>>b;
 }

 while(b>a)
 {
  cout<<"大了"<<endl;
  cin>>b;
 }
 }
}

0 0
原创粉丝点击