C++ write a game for guess computer generated than 10000 quite funny

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

void game6();

int main()
{
    game6();
    return 0;
}

void game6()
{
    srand(time(NULL));
    int computerNum=rand()%10000;

    //User inputs a guessed number
    int userNum;
    cout<<"Please enter a number between 1 and 10000: ";
    cin>>userNum;    

    //Run the WHILE loop
    while(userNum!=computerNum)
    {
        cout<<userNum<<" is ";
        if(userNum>computerNum)
        {
            cout<<" greater ";
        }
        else
        {
            cout<<"less";
        }
        cout<<" than computer's number!"<<endl;
        cout<<"Choose another number:";
        cin>>userNum;
    }
    cout<<"Yeeaayy..You've got the number."<<endl;
}

 

Compile

g++ -g h1.cpp -o a

Run ./a

 

posted @ 2022-01-21 11:33  FredGrit  阅读(22)  评论(0编辑  收藏  举报