请问在下面这个“猜数字游戏”代码中怎么限定玩家猜测的次数,比如我希望在玩家猜测5次的时候显示游戏失败,那该如何添加代码呢?
int main()
{
srand((unsigned int)time(NULL));
int num = rand() % 100 + 1;
cout << num << endl;
int a = 0;
while (1)
{
cin >> a;
if (a > num)
{
cout << "猜测过大" << endl;
}
else if (a < num)
{
cout << "猜测过小" << endl;
}
else
{
cout << "恭喜您猜对了" << endl;
break;
}
}
system("pause");
return 0;
}