第二题:1~100之间猜数。
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
int m;
char ch;
int n = rand() % 100;
cout << n << endl;
while (true)
{
cout << "猜数字1-100:";
cin >> m;
if (m == n) {
cout << "正确的!";
break;
}
else {
cout << "是否继续:y or n:";
cin >> ch;
if (ch == 'y') continue;
else break;
}
}
}