C++猜数字小游戏

#include<iostream>
using namespace std;

int main()
{
    srand((unsigned int)time(NULL));
    int number;
    number=rand()%100;              //生成0~99的数字;
    int guess_number;
    int time=0;

    cout<<"输一个100内的数字猜猜看吧"<<endl;
    while (1)
    {        
        cin>>guess_number;

        if(guess_number!=number)
        {
            time++;
            if(guess_number>number)
            {
                cout<<"你猜大了"<<endl;
            }
            else
            {
                cout<<"你猜小了"<<endl;
            }        
        }
        else if(time==0)
        {
            cout<<"狗东西你居然一次就猜对了"<<endl;
            break;
        }
        else
        {
            cout<<"你个笨比"<<time<<"次才猜对"<<endl;
            break;
        }        
    }    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hyby/p/13401231.html