豆包挺好用的,但还是自己写的玩的更带劲,也不知到干什么……
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
while(true)
{
int ans = rand()%100 + 1;
int g,cnt=0;
cout << "===== 猜数游戏 1-100 =====" << endl;
while(true)
{
cout << "请输入数字:";
cin >> g;
cnt++;
if(g>ans) cout << "大了" << endl;
else if(g<ans) cout << "小了" << endl;
else
{
cout << "猜对了!共" << cnt << "次" << endl;
break;
}
}
char c;
cout << "再来一局?";
cin >> c;
if(c=='n'||c=='N') break;
}
return 0;
}