鱼C论坛

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

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

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

你的错误,已经帮你修改了,现在可以玩了


  1. #include<stdio.h>       // stdio.h 头文件是系统自带,用尖括号,不用引号
  2. #include<conio.h>      // getch() 需要这个头文件
  3. void main()
  4. {
  5.           int total = 21;
  6.           int shengyu,yours,computer;
  7.           char another;
  8.           
  9.           printf("****************************************\n");
  10.           printf("*****     起始牙签个数为%d         *****\n",total);
  11.           printf("*****     每次只能拿走1-3个        *****\n");
  12.           printf("*****     谁拿最后一个谁就输了     *****\n");
  13.           printf("\n");
  14.           printf("\n明白了?按任意键开始吧......");
  15.           
  16.           getch();         // 没有添加头函数 conio.h
  17.           shengyu = total;

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

  25.                       if(yours >= 1 && yours <= 3)
  26.                             break;
  27.                       else
  28.                             printf("你每次只能拿1到3个。\n");
  29.                }while(1);
  30.                        
  31.                shengyu = shengyu - yours;
  32.                if(shengyu < 0)
  33.               {
  34.                      printf("\n\n你不按规则来呀! \n");
  35.                      shengyu = shengyu + yours;
  36.                      continue;
  37.                }
  38.                if(shengyu == 0)
  39.                {
  40.                      printf("你输了,再来不? (Y/N)");
  41.                      //清缓冲区
  42.                      fflush(stdin);
  43.                            another = getchar();
  44.                                   
  45.                      if(another =='Y' || another == 'y')
  46.                     {
  47.                            shengyu = total;
  48.                     }
  49.                     else
  50.                     {
  51.                            printf("\n\n再见,以后再来玩呀!\n");
  52.                            break;
  53.                     }
  54.                }
  55.                else
  56.                {
  57.                            computer = 4 - yours;
  58.                            printf("\n电脑拿走了%d个牙签\n",computer);
  59.                            shengyu = shengyu - computer;
  60.                }
  61.          }
  62. }
复制代码
9BE6DA00-0CB2-4962-904C-DBE43DED96D3.png
52833922-6FAF-48FC-BC2C-4DEFF92BF3CF.png

最佳答案

查看完整内容

你的错误,已经帮你修改了,现在可以玩了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

你的错误,已经帮你修改了,现在可以玩了


  1. #include<stdio.h>       // stdio.h 头文件是系统自带,用尖括号,不用引号
  2. #include<conio.h>      // getch() 需要这个头文件
  3. void main()
  4. {
  5.           int total = 21;
  6.           int shengyu,yours,computer;
  7.           char another;
  8.           
  9.           printf("****************************************\n");
  10.           printf("*****     起始牙签个数为%d         *****\n",total);
  11.           printf("*****     每次只能拿走1-3个        *****\n");
  12.           printf("*****     谁拿最后一个谁就输了     *****\n");
  13.           printf("\n");
  14.           printf("\n明白了?按任意键开始吧......");
  15.           
  16.           getch();         // 没有添加头函数 conio.h
  17.           shengyu = total;

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

  25.                       if(yours >= 1 && yours <= 3)
  26.                             break;
  27.                       else
  28.                             printf("你每次只能拿1到3个。\n");
  29.                }while(1);
  30.                        
  31.                shengyu = shengyu - yours;
  32.                if(shengyu < 0)
  33.               {
  34.                      printf("\n\n你不按规则来呀! \n");
  35.                      shengyu = shengyu + yours;
  36.                      continue;
  37.                }
  38.                if(shengyu == 0)
  39.                {
  40.                      printf("你输了,再来不? (Y/N)");
  41.                      //清缓冲区
  42.                      fflush(stdin);
  43.                            another = getchar();
  44.                                   
  45.                      if(another =='Y' || another == 'y')
  46.                     {
  47.                            shengyu = total;
  48.                     }
  49.                     else
  50.                     {
  51.                            printf("\n\n再见,以后再来玩呀!\n");
  52.                            break;
  53.                     }
  54.                }
  55.                else
  56.                {
  57.                            computer = 4 - yours;
  58.                            printf("\n电脑拿走了%d个牙签\n",computer);
  59.                            shengyu = shengyu - computer;
  60.                }
  61.          }
  62. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-6 05:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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