猜数字代码

来源:互联网 发布:预决算软件有哪些 编辑:程序博客网 时间:2024/05/29 12:28

#include <iostream>
include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
   srand(time(0));
   int theNumber=rand()%100+1;
   int tries=0,guess;
   cout<<"欢迎来猜数字"<<endl<<endl;
   do
   {
      cout<<"enter a number between 1~100"<<endl;
   cin>>guess;
   ++tries;
   if(guess>theNumber)
    cout<<"too high"<<endl;
       if(guess<theNumber)
    cout<<"too low"<<endl;   
  
  
   }while(guess!=theNumber);
   cout<<"the number of your try  "<<tries<<endl;

   return 0;

}

原创粉丝点击