#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<iostream>
#define q system("cls")
using namespace std;
int main() {
for (int i = 10; i > 0; i--) {
cout << "key:" << i << endl;
cout << "随机数游戏" << endl;
cout << "1.猜数字" << endl;
cout << "2.数字炸弹(推荐)" << endl;
cout << "你可以戏耍系统,但请不要不慎失败" << endl;
char xiangmu;
cout << "请输入" << endl;
xiangmu=getchar();
cout << "一秒后为您跳转";
Sleep(1000);
q;
switch(xiangmu){
case 1:
srand((unsigned)time(NULL));
int cai, max0, min0;
cout << "你要从一猜到几?" << endl;
int num;
cin >> num;
max0 = num;
min0 = 1;
if (num <= 32) {
i++;
cout << "不许躺平!" << endl;
continue;
}
cai = rand() % num;
cout << "开始猜吧" << endl;
int jihui = 5;
while (jihui--) {
int a;
cin >> a;
if (a < min0 || a > max0) {
cout << "ah-oh" << endl;
} else if (a < cai) {
cout << "It's too small." << endl;
cout << "您当前还剩" << jihui << "次机会" << endl;
min0 = a + 1;
} else if (a > cai) {
cout << "It's too big." << endl;
cout << "您当前还剩" << jihui << "次机会" << endl;
max0 = a - 1;
} else {
cout << "成功" << endl;
i++;
Sleep(5000);
break;
}
if (jihui == 0) {
cout << "失败" << endl;
Sleep(3000);
break;
}
cout << min0 << "到" << max0 << endl;
break;
case '2':
{srand((unsigned)time(NULL));
int cai;
cout << "你要从一猜到几?" << endl;
int num;
cin >> num;
if (num < 32) {
i++;
cout << "不许躺平!" << endl;
continue;
}
rand() % num;
cout << "开始猜吧" << endl;
int minn = 0, maxx = num ;
while (1) {
cout << minn << "到" << maxx << endl;
int a;
cin >> a;
if (a == maxx && a == minn && a == cai) {
i++;
cout << "胜利" << endl;
Sleep(3000);
break;
} else if (a < minn && a > maxx) {
cout << "ah-oh";
} else if (a < cai) {
cout << "It's too small.";
minn = a + 1;
} else if (a > cai) {
cout << "It's too big.";
maxx = a - 1;
} else if (a == cai && (a < maxx || a > minn)) {
cout << "boom" << endl;
cout << "defeat" << endl;
Sleep(5000);
break;
}
cout << endl;
}
break;}
default:
goto end;
q;
}
end:
q;
cout << "此次游戏机会已用尽";
return 0;
}
3 个赞
代码报错给你改好了
#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<iostream>
#define q system("cls")
using namespace std;
int main() {
for (int i = 10; i > 0; i--) {
cout << "key:" << i << endl;
cout << "随机数游戏" << endl;
cout << "1.猜数字" << endl;
cout << "2.数字炸弹(推荐)" << endl;
cout << "你可以戏耍系统,但请不要不慎失败" << endl;
char xiangmu;
cout << "请输入" << endl;
xiangmu=getchar();
cout << "一秒后为您跳转";
Sleep(1000);
q;
int cai, max0, min0;
int num;
int jihui = 5;
switch(xiangmu){
case 1:
srand((unsigned)time(NULL));
cout << "你要从一猜到几?" << endl;
cin >> num;
max0 = num;
min0 = 1;
if (num <= 32) {
i++;
cout << "不许躺平!" << endl;
continue;
}
cai = rand() % num;
cout << "开始猜吧" << endl;
while (jihui--) {
int a;
cin >> a;
if (a < min0 || a > max0) {
cout << "ah-oh" << endl;
} else if (a < cai) {
cout << "It's too small." << endl;
cout << "您当前还剩" << jihui << "次机会" << endl;
min0 = a + 1;
} else if (a > cai) {
cout << "It's too big." << endl;
cout << "您当前还剩" << jihui << "次机会" << endl;
max0 = a - 1;
} else {
cout << "成功" << endl;
i++;
Sleep(5000);
break;
}
if (jihui == 0) {
cout << "失败" << endl;
Sleep(3000);
break;
}
cout << min0 << "到" << max0 << endl;
}
break;
case '2':
{srand((unsigned)time(NULL));
int cai;
cout << "你要从一猜到几?" << endl;
int num;
cin >> num;
if (num < 32) {
i++;
cout << "不许躺平!" << endl;
continue;
}
rand() % num;
cout << "开始猜吧" << endl;
int minn = 0, maxx = num ;
while (1) {
cout << minn << "到" << maxx << endl;
int a;
cin >> a;
if (a == maxx && a == minn && a == cai) {
i++;
cout << "胜利" << endl;
Sleep(3000);
break;
} else if (a < minn && a > maxx) {
cout << "ah-oh";
} else if (a < cai) {
cout << "It's too small.";
minn = a + 1;
} else if (a > cai) {
cout << "It's too big.";
maxx = a - 1;
} else if (a == cai && (a < maxx || a > minn)) {
cout << "boom" << endl;
cout << "defeat" << endl;
Sleep(5000);
break;
}
cout << endl;
}
break;}
default:
goto end;
}
q;
}
end:
q;
cout << "此次游戏机会已用尽";
return 0;
}
4 个赞
是变量定义位置错误和少写了几个反括号造成的
3 个赞
非常感谢!
3 个赞