今天学了一个用代码写的猜数字小游戏
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf(" 1.play 0.exit \n");
}
void game()
{ int ret;
int guess;
ret=rand()%100+1;
while(1)
{
printf(“猜猜\n”);
scanf("%d",&guess);
if (guess>ret) {printf(“大了大了\n”);}
else if (guess<ret) {printf(“小了小了\n”);}
else {printf(“猜对了,你真牛逼\n”); break;}
}
}
int main()
{ int input=0;
srand((unsigned int)time(NULL));
do{
menu();
printf(“请选择>:”);
scanf("%d",&input);
switch(input)
{
case 1:
game();
break;
case 0:
printf(“退出游戏\n”);
break;
default:
printf(“请重新选择\n”);
break;
}
}while (input);
printf(“游戏结束”);
return 0;
}
又比昨天牛逼了一点