鱼C论坛

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

猜拳小游戏

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

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

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

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

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

char *str[] = {"none","剪刀","石头","布"};
void game(int);
int count = 0;
//机器出拳,并判断输赢
void game(int choice){
        int it;
        time_t t; 
        srand((unsigned)time(&t));//真神奇
        it = (int)(rand() % 4);
        if (it != 0){
                if (it == choice){
                        printf("你出%s,我出%s,咱打平!\n",str[choice],str[it]); 
                        count += 0;
                }
                else{
                        switch(choice){
                                case 1:{
                                        if (it == 2){
                                                printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
                                                count -= 1;
                                        }
                                        
                                        if (it == 3){
                                                printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
                                                count += 1;
                                        }
                                        break; 
                                }
                                case 2:{
                                        if (it == 3){
                                                printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
                                                count -= 1;
                                        }
                                        
                                        if (it == 1){
                                                printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
                                                count += 1;
                                        }
                                        break;
                                } 
                                case 3:{
                                        if (it == 1){
                                                printf("你出%s,我出%s,我赢了!\n",str[choice],str[it]);
                                                count -= 1;
                                        }
                                        
                                        if (it == 2){
                                                printf("你出%s,我出%s,我输了!\n",str[choice],str[it]);
                                                count += 1;
                                        }
                                        break;
                                }
                                default: break;
                        }
                }
        }
        else{
                game(choice);
        }
        
}
//主函数 用户出拳,调用game()函数
int main(void){
         printf("######################\n"); 
         printf("##欢迎来到猜拳小游戏##\n");
         printf("######################\n");
         int choice;
         do{
                 printf("请出拳(1剪刀/2石头/3布/0退出)-->");
                 scanf("%d", &choice);
                 game(choice);
                        
         } while(choice != 0);
        
        if(count >= 1){
                printf("你赢了\n");
        }
        if(count == 0){
                printf("平局\n");
        } 
        if (count < 0){
                printf("你输了\n");
        }
        return 0;
}

正常输入3却结束运行

正常输入3却结束运行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-10 15:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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