首页 > 其他分享 >猜数字游戏(好难,会再战!)

猜数字游戏(好难,会再战!)

时间:2022-10-24 15:32:26浏览次数:181  
标签:guess 游戏 int 好难 ret break printf input 再战

void menu()

{

printf("##############################\n");

printf("##### 1.play      0.exit #####\n");  

printf("##############################\n");

}

//RAND_MAX

void game()

{

int ret = 0;

int guess = 0;

//srand((unsigned int)time(NULL));

 ret = rand()%100+1;

 while (1)

 {

  printf("猜数字:>");

  scanf("%d", &guess);

  if (guess > ret)

  {

   printf("猜大了\n");

  }

  else if (guess < ret)

  {

   printf("猜小了\n");

  }

  else

  {

   printf("恭喜你,猜对了\n");

   break;

  }

 }

printf("%d\n", ret);

//printf("猜数字\n");

}

int main()

{

srand((unsigned int)time(NULL));

int input = 0;

do

{

 menu();

  printf("请选择>:");

 scanf("%d", &input);

 switch (input)

 {

 case 1:

   game();

   break;

 case 0:

    printf("退出游戏\n");

    break;

 default:

    printf("选择错误\n");

    break;


 }


} while (input);

return 0;

}

{

int l = 0;

for (l = 1; l <= 9; l++)

{

 int h = 1;

 for (h = 1; h <= l; h++)

 {

  printf("%d*%d=%-2d ", l, h, l * h);

 }

 printf("\n");

}

标签:guess,游戏,int,好难,ret,break,printf,input,再战
From: https://blog.51cto.com/u_15838933/5789926

相关文章