#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int game(int x) {
int r = 0;
r=rand()%100+1;
while (1) {
printf("请输入你想要猜的数值:\n");
scanf_s("%d", &x);
if (x == r) {
printf("恭喜猜中\n");
break;
}
else if (x < r) {
printf("小了,请往大猜\n");
}
else {
printf("大了,请往小处猜\n");
}
}
}
int main() {
int a = 0;
int sel = 0;
int n = 0;
srand((unsigned int)time(NULL));
do {
printf("############################\n");
printf("###### 1.play 0.end ######\n");
printf("############################\n");
printf("请选择:");
scanf_s("%d", &sel);
switch (sel) {
case 1:
game(a);
n++;
printf("恭喜您已经通关%d次\n",n);
break;
case 0:
printf("退出游戏");
break;
default:
printf("请重新输入0/1\n");
break;
}
} while (sel);
return 0;
}