在数字游戏的基础上,
#include <iostream>
#include<ctime>
using namespace std;
int main()
{
srand((unsigned int)time(NULL));//添加随机数种子
int num = rand() % 100 + 1;//生成1-100随机数
//cout << "num" << num << endl;
int aidcount;
cin >> aidcount;//目标猜测次数
int count = 0;
//cout << num << endl;
int val = 0;
while (1)
{
cin >> val;
count++;
if (val > num)
{
cout << "猜测过大" << endl;
}
else if (val < num)
{
cout << "猜测过小" << endl;
}
else
{
cout << "恭喜您猜对了" << endl;
break;
}
if (count > aidcount)
{
cout << "false" << endl;
break;
}
}
cout << count << endl;
system("pause");
return 0;
}
添加了自己设置游戏次数!