//猜数字游戏
2018.3.21
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu()//生成菜单
{
printf ("****************************\n");
printf ("****** 猜 数 字 游 戏 ******\n");
printf ("****** 1、玩 游 戏 ******\n");
printf ("****** 0、退 出 游 戏 ******\n");
printf ("****************************\n");
}
void game()
{
int i = rand()%100;
int j = 0;
printf ("你猜啊: ");
while(1)
{
scanf ("%d",&j);
if (j > i)
{
printf ("大了");
}
else if (j < i)
{
printf ("小了");
}
else
{
printf ("恭喜你猜对了!!!\n");
break;
}
printf (",你再猜:\n");
}
}
#include <stdlib.h>
#include <time.h>
void menu()//生成菜单
{
printf ("****************************\n");
printf ("****** 猜 数 字 游 戏 ******\n");
printf ("****** 1、玩 游 戏 ******\n");
printf ("****** 0、退 出 游 戏 ******\n");
printf ("****************************\n");
}
void game()
{
int i = rand()%100;
int j = 0;
printf ("你猜啊: ");
while(1)
{
scanf ("%d",&j);
if (j > i)
{
printf ("大了");
}
else if (j < i)
{
printf ("小了");
}
else
{
printf ("恭喜你猜对了!!!\n");
break;
}
printf (",你再猜:\n");
}
}
int main()
{
srand((unsigned )time (NULL));
menu();
again:
printf ("请选择是否开始游戏:\n 1(开始)/0(不开始):");
int i;
scanf ("%d",&i);
switch (i)
{
case 1: game();
goto again;
break;
case 0: printf ("结束游戏\n");
break;
default: printf ("你的输入有误,请重新选择:\n");
goto again;
break;
}
{
srand((unsigned )time (NULL));
menu();
again:
printf ("请选择是否开始游戏:\n 1(开始)/0(不开始):");
int i;
scanf ("%d",&i);
switch (i)
{
case 1: game();
goto again;
break;
case 0: printf ("结束游戏\n");
break;
default: printf ("你的输入有误,请重新选择:\n");
goto again;
break;
}
system ("pause");
return 0;
}
return 0;
}