|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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却结束运行
|