- meishuai's blog
c++游戏(自编)
- 2024-5-24 13:44:40 @
猜数字
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
class Creature {
public:
void cai(){
int n;
cout << "输出0~100000" << endl;
int dashabi = 0;
dashabi = rand() % 100000 + 0;
while(n != dashabi){
cin >> n;
system("cls");
if(n > dashabi){
cout << "大了" << endl;
}if(n < dashabi && n >= 0 && n <= 100000){
cout << "小了" << endl;
}if(n == dashabi){
cout << "你猜中了!!!" << endl;
break;
}if(n < 0 || n > 100000){
cout << "你有病吧!!都说了输出0~100000的数,你还乱输" << endl;
}
}
}
};
Creature initialCreature;
int main (){
srand((unsigned)time(0));
while(true){
cout << "开始?" << endl;
int a;
cout << "1.ok" << endl;
cin >> a;
system("cls");
switch(a){
case 1:
initialCreature.cai();
break;
}
}
return 0;
}