#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand((unsigned int)time(NULL));//用来选取一个随机数,所选取的数作为要被猜的数
int num = rand()%100+1;//这个数是在1--100之间的;如果不+1的话范围就是0--99;rand()%后面是
int a,b=0; //多少,就是0--多少之间的随机数
while(b<5)//允许猜错的次数:5次
{
cin>>a;
b++;
if(a==num)
{
cout<<"恭喜你答对啦"<<endl;
cout<<"\a"<<endl;//发出声音
break;
}else if(a>num)
{
cout<<"猜测过大"<<endl;
}else if(a<num)
{
cout<<"猜测过小"<<endl;
}
}
}
猜数字游戏
最新推荐文章于 2025-05-01 00:33:34 发布