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;
}

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>