直接上代码(输字母或符号也会被踢)
#include<bits/stdc++.h>//作者懒得写,就用万能头了
using namespace std;
unsigned times, seed;
long long sw;
int daan, randd, cs, zqs;
int main(){
for(int i=1;i<=25;i++){
cout<<"资源加载中......"<<i*4<<"%";
system("cls");
}
while(1){
cout<<"请问你要玩多少数字以内的猜数字?"<<endl;
cout<<"(温馨提示:如果数大于或等于10000时会因为被识别成捉弄服务器而被强制退出)"<<endl;
cin>>sw;
system("cls");
if(sw>=10000){
cout<<"你已被踢出游戏。";
return 0;
}
times=time(0);
seed=times;
srand(seed);
randd=rand()%sw;
cout<<"请输入一个小于"<<sw<<"的数。"<<endl<<"注意:不要超过"<<sw<<"!!!"<<endl;
for(;;){
cin>>daan;
cs++;
if(daan>=sw){
cout<<"你已被踢出游戏。";
return 0;
}
if(daan==randd){
cout<<"恭喜, 你猜对了!";
_sleep(1000);
zqs++;
break;
}
if(daan>=randd){
cout<<" 猜大了"<<endl;
_sleep(1000);
}
else{
cout<<"猜小了"<<endl;
_sleep(1000);
}
}
system("cls");
cout<<"请问是否继续游戏?"<<endl<<"是按1, 否按2。"<<endl;
cin>>daan;
if(daan==1){
}
else{
if(daan==2){
break;
}
else{
for(int i=1;i<=3;i++){
system("cls");
cout<<"请勿输入其他数字!!!"<<endl;
_sleep(1000);
cin>>daan;
if(daan==1){
break;
}
else{
if(daan==2){
break;
}
else{
}
}
}
cout<<"你已被踢出游戏。";
return 0;
}
}
if(daan==2){
break;
}
system("cls");
}
system("cls");
cout<<"谢谢游玩!";
system("cls");
cout<<"汇总:"<<endl;
cout<<"你一共尝试了"<<cs<<"次";
cout<<endl<<"你一共答对了"<<zqs<<"题";
_sleep(5000);
return 0;
}
如果有BUG或有优化处请在评论区告诉作者哦