• 游戏
• ## 猜数字游戏

• @ 2021-09-18 23:35:35

``````#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 条评论

• @ 2021-10-11 17:10:24

"Eazy" 难道不是Easy吗

• @ 2021-09-22 22:19:26

qp

• 1