c++写的猜数字代码
#include<iostream>
#include<iostream>
using namespace std;
int main()
{
srand((unsigned int)time(NULL));//跟随系统时间随机生成数字
int a = 0;
int num = 0;
int b = rand() % 100 + 1;
cout << "请输入一个整数0-100" << endl;
cin >> a;
while (a != b)
{
if (num < 4)
{
if (a > b)
{
cout << "猜测过大!!!" << endl;
}
else if(a<b)
{
cout << "猜测过小!!!" << endl;
}
else
{
cout << "猜对了!!!" << endl;
}
cin >> a;
num++;
}
else
{
cout << "失败!!!" << endl;
break;
}
}
system("pause");
return 0;
}