猜数字

来源:互联网 发布:点点客工作 知乎 编辑:程序博客网 时间:2024/06/06 04:15

/*
 *Copyright(c)2016,LynseyListening
 *All rights reserced.
 *文件名称:listening.cpp
 *作者    :陈旭
 *完成日期:2016.3.24
 *版本号  :vc++6.0
*/
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
 int x;
 int a;
 srand(time(NULL));
 a=rand()%1000;
 while(1)
 {
  cout<<"请输入您猜的数:"<<endl;
  cin>>x;
  if(x>a)
   cout<<"大了"<<endl;
  else if(x<a)
   cout<<"小了"<<endl;
  else
  {
   cout<<"猜对了"<<endl;
   break;
  }
 }
 return 0;
}

运行结果:

0 0
原创粉丝点击