1000以内猜数游戏
轻松锻炼二分思维!
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand(unsigned(time(NULL)));
int sj=rand()%1000+1,ci=-1;
cout<<"It's bigger than 0,and smaller than 1001."<<endl;
while(ci!=sj)
{
cout<<"Set your number:";
cin>>ci;
if(ci==sj)
{
cout<<"That's right!You win!"<<endl;
break;
}
if(ci>sj)
{
cout<<"Too big!"<<endl;
}
else
{
cout<<"Too small!"<<endl;
}
}
cout<<"Bye!"<<endl;
return 0;
}