案例描述:系统随机生成一个1到100之间的数字,玩家进行猜测,如果猜错,提示玩家数字过大或过小,如果猜对恭喜玩家胜利,并且退出游戏
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
cout << "请玩家输入一个数字";
int sum1;
sum1 = rand() % 100 + 1;
while (1)
{
cin >> sum;
if (sum > sum1)
{
cout << "数字过大" << endl;
}
else if (sum < sum1)
{
cout << "数字过小" << endl;
}
else
{
cout << "恭喜玩家胜利" << endl;
break;
}
}
system("pause");
return 0;
}