鱼C论坛

 找回密码
 立即注册
查看: 1035|回复: 1

[已解决]看一下有没有错,在外面,没有电脑

[复制链接]
发表于 2020-10-10 12:08:12 | 显示全部楼层 |阅读模式
9鱼币
看一下代码有没有错,在外面,没有电脑
最佳答案
2020-10-10 12:08:13
本帖最后由 风过无痕1989 于 2020-10-10 13:27 编辑

你的错误,已经帮你修改了,现在可以玩了
#include<stdio.h>       // stdio.h 头文件是系统自带,用尖括号,不用引号
#include<conio.h>      // getch() 需要这个头文件 
void main()
{
          int total = 21;
          int shengyu,yours,computer;
          char another;
          
          printf("****************************************\n");
          printf("*****     起始牙签个数为%d         *****\n",total);
          printf("*****     每次只能拿走1-3个        *****\n");
          printf("*****     谁拿最后一个谁就输了     *****\n");
          printf("\n");
          printf("\n明白了?按任意键开始吧......");
          
          getch();         // 没有添加头函数 conio.h
          shengyu = total;

          while(shengyu != 0)
         {
               do               //只能拿1-3个
               {
                      printf("\n当前牙签数为%d\n",shengyu);
                      printf("请输入你拿走的牙签数(1-3): ");
                      scanf("%d",&yours);

                      if(yours >= 1 && yours <= 3)
                            break;
                      else
                            printf("你每次只能拿1到3个。\n");
               }while(1);
                        
               shengyu = shengyu - yours;
               if(shengyu < 0)
              {
                     printf("\n\n你不按规则来呀! \n");
                     shengyu = shengyu + yours;
                     continue;
               }
               if(shengyu == 0)
               {
                     printf("你输了,再来不? (Y/N)");
                     //清缓冲区
                     fflush(stdin);
                           another = getchar();
                                  
                     if(another =='Y' || another == 'y')
                    {
                           shengyu = total;
                    }
                    else
                    {
                           printf("\n\n再见,以后再来玩呀!\n");
                           break;
                    }
               }
               else
               {
                           computer = 4 - yours;
                           printf("\n电脑拿走了%d个牙签\n",computer);
                           shengyu = shengyu - computer;
               }
         }
}
9BE6DA00-0CB2-4962-904C-DBE43DED96D3.png
52833922-6FAF-48FC-BC2C-4DEFF92BF3CF.png

最佳答案

查看完整内容

你的错误,已经帮你修改了,现在可以玩了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-10-10 12:08:13 | 显示全部楼层    本楼为最佳答案   
本帖最后由 风过无痕1989 于 2020-10-10 13:27 编辑

你的错误,已经帮你修改了,现在可以玩了
#include<stdio.h>       // stdio.h 头文件是系统自带,用尖括号,不用引号
#include<conio.h>      // getch() 需要这个头文件 
void main()
{
          int total = 21;
          int shengyu,yours,computer;
          char another;
          
          printf("****************************************\n");
          printf("*****     起始牙签个数为%d         *****\n",total);
          printf("*****     每次只能拿走1-3个        *****\n");
          printf("*****     谁拿最后一个谁就输了     *****\n");
          printf("\n");
          printf("\n明白了?按任意键开始吧......");
          
          getch();         // 没有添加头函数 conio.h
          shengyu = total;

          while(shengyu != 0)
         {
               do               //只能拿1-3个
               {
                      printf("\n当前牙签数为%d\n",shengyu);
                      printf("请输入你拿走的牙签数(1-3): ");
                      scanf("%d",&yours);

                      if(yours >= 1 && yours <= 3)
                            break;
                      else
                            printf("你每次只能拿1到3个。\n");
               }while(1);
                        
               shengyu = shengyu - yours;
               if(shengyu < 0)
              {
                     printf("\n\n你不按规则来呀! \n");
                     shengyu = shengyu + yours;
                     continue;
               }
               if(shengyu == 0)
               {
                     printf("你输了,再来不? (Y/N)");
                     //清缓冲区
                     fflush(stdin);
                           another = getchar();
                                  
                     if(another =='Y' || another == 'y')
                    {
                           shengyu = total;
                    }
                    else
                    {
                           printf("\n\n再见,以后再来玩呀!\n");
                           break;
                    }
               }
               else
               {
                           computer = 4 - yours;
                           printf("\n电脑拿走了%d个牙签\n",computer);
                           shengyu = shengyu - computer;
               }
         }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-10 10:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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