规则介绍
系统随机生成一个1~100的数字,玩家输入答案,每次提示过大还是过小,如果五次还没猜出来,则为失败。
以下为源代码
#include<iostream>
using namespace std;
#include<ctime>
int main()
{
srand((unsigned int)time(NULL));
int num = rand() % 100 + 1;
int a;
int x = 0;
while (x < 5)
{
cin >> a;
x++;
if (a > num)
{
cout << "过大" << endl;
}
else if (a < num)
{
cout << "过小" << endl;
}
else
{
cout << "恭喜!挑战成功!" << endl;
break;
}
}
cout << "挑战失败!" << endl;
system("pause");
return 0;
}
小白c++学习,如有错误,请指正,谢谢!