#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int get_magic(){
srand((unsigned)time(0));
return(rand()%1000+1);
}
int main(){
int magic,n,t=0;
char a;
srand((unsigned)time(0));
magic= get_magic();
while(1){
cout<<"a number between 1 and 1000, type your guess"<<endl;
cin>>n;
t++;
if(n>magic) cout<<"Too high,Try again"<<endl;
else if(n<magic) cout<<"Too low,Try again"<<endl;
else {
if(t<10) cout<<"either you know the secret or you got lucky!"<<endl;
else if(t==10) cout<<"ahah!you know the secret!"<<endl;
else cout<<"you should be able to do better!"<<endl;
cout<<"Excellent,Play again(y or n)"<<endl;
cin>>a;
if(a=='y'){
t=0;
magic=get_magic();
}
else break;
}
}
return 0;
}
猜数字大小(多次游戏)
最新推荐文章于 2024-11-09 20:38:27 发布
这是一个简单的C++程序,实现了一个猜数字游戏。用户需在1到1000之间猜测一个随机数,程序会提供过高或过低的提示。如果在10次内猜中,程序会给出特殊反馈,用户可以选择是否重玩。
摘要由CSDN通过智能技术生成