鱼C论坛

 找回密码
 立即注册
查看: 1188|回复: 0

猜拳小游戏

[复制链接]
发表于 2020-4-4 18:27:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 乱码zzz 于 2020-4-4 18:28 编辑

可以运行,调试的时候也没有出错
但是运行着运行着却会出现图片所示问题(图片在最下方)(正常输入3,但程序却停止了)
这究竟是为什么qwq
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>

  4. char *str[] = {"none","剪刀","石头","布"};
  5. void game(int);
  6. int count = 0;
  7. //机器出拳,并判断输赢
  8. void game(int choice){
  9.         int it;
  10.         time_t t;
  11.         srand((unsigned)time(&t));//真神奇
  12.         it = (int)(rand() % 4);
  13.         if (it != 0){
  14.                 if (it == choice){
  15.                         printf("你出%s,我出%s,咱打平!\n",str[choice],str[it]);
  16.                         count += 0;
  17.                 }
  18.                 else{
  19.                         switch(choice){
  20.                                 case 1:{
  21.                                         if (it == 2){
  22.                                                 printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
  23.                                                 count -= 1;
  24.                                         }
  25.                                        
  26.                                         if (it == 3){
  27.                                                 printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
  28.                                                 count += 1;
  29.                                         }
  30.                                         break;
  31.                                 }
  32.                                 case 2:{
  33.                                         if (it == 3){
  34.                                                 printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
  35.                                                 count -= 1;
  36.                                         }
  37.                                        
  38.                                         if (it == 1){
  39.                                                 printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
  40.                                                 count += 1;
  41.                                         }
  42.                                         break;
  43.                                 }
  44.                                 case 3:{
  45.                                         if (it == 1){
  46.                                                 printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
  47.                                                 count -= 1;
  48.                                         }
  49.                                        
  50.                                         if (it == 2){
  51.                                                 printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
  52.                                                 count += 1;
  53.                                         }
  54.                                         break;
  55.                                 }
  56.                                 default: break;
  57.                         }
  58.                 }
  59.         }
  60.         else{
  61.                 game(choice);
  62.         }
  63.        
  64. }
  65. //主函数 用户出拳,调用game()函数
  66. int main(void){
  67.         printf("######################\n");
  68.         printf("##欢迎来到猜拳小游戏##\n");
  69.         printf("######################\n");
  70.         int choice;
  71.          do{
  72.                  printf("请出拳(1剪刀/2石头/3布/0退出)-->");
  73.                  scanf("%d", &choice);
  74.                  game(choice);
  75.                        
  76.          } while(choice != 0);
  77.        
  78.         if(count >= 1){
  79.                 printf("你赢了\n");
  80.         }
  81.         if(count == 0){
  82.                 printf("平局\n");
  83.         }
  84.         if (count < 0){
  85.                 printf("你输了\n");
  86.         }
  87.         return 0;
  88. }
复制代码


正常输入3却结束运行

正常输入3却结束运行
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 18:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表