普通猜数字,还行吧。

#include <bits/stdc++.h>
using namespace std;
void Eazy(){
    int a=rand()%99+1;
    while(true){
        cout<<"This is a number in 1 to 100."<<endl<<"Guess it:";
        int h;
        cin>>h;
        if(h==a){
            cout<<"Congratulations!"<<endl;
            break;
        }else if(h<a){
            cout<<"Sorry,you guess are small."<<endl;
        }else if(h>a){
            cout<<"Sorry,you guess are big."<<endl;
        }
    }
}
void Normal(){
    int a=rand()%999+1;
    while(true){
        cout<<"This is a number in 1 to 1000."<<endl<<"Guess it:";
        int h;
        cin>>h;
        if(h==a){
            cout<<"Congratulations!"<<endl;
            break;
        }else if(h<a){
            cout<<"Sorry,you guess are small."<<endl;
        }else if(h>a){
            cout<<"Sorry,you guess are big."<<endl;
        }
    }
}
void Hard(){
    int a=rand()%9999+1;
    while(true){
        cout<<"This is a number in 1 to 10000."<<endl<<"Guess it:";
        int h;
        cin>>h;
        if(h==a){
            cout<<"Congratulations!"<<endl;
            break;
        }else if(h<a){
            cout<<"Sorry,you guess are small."<<endl;
        }else if(h>a){
            cout<<"Sorry,you guess are big."<<endl;
        }
    }
}
int main(){
    srand(time(0));
    while(true){
        cout<<"Guess number!"<<endl<<"1) Eazy"<<endl<<"2) Normal"<<endl<<"3) Hard"<<endl<<"4) Exit"<<endl<<"Please select(1-4):";
        int h;
        cin>>h;
        if(h<1 || h>4) cout<<"Incorrect input!"<<endl;
        else{
            if(h==1) Eazy();
            else if(h==2) Normal();
            else if(h==3) Hard();
            else break;
        }
    }
    return 0;
}

2 条评论

  • 1