Grey_Fate 2021-11-25 20:10 采纳率: 100%
浏览 45
已结题

学校留的一个C语言编写的石头剪刀布小游戏习题,有哪位可以指导一下错在哪里吗

问题遇到的现象和发生背景

学校的要求练习

问题相关代码,请勿粘贴截图
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <time.h>
int main()
{
    int computerNumber,userNumber;
    char ch='y';
    bool IsContine=true;
    while(IsContine)
        {
        srand(time(NULL));
        computerNumber=(int)(rand()%3);
        printf("请输入用户你的选择:0-剪刀 1-石头 2-布\n");
        scanf("%d",&computerNumber);
        switch(computerNumber)
        {
            case 0:
                if(userNumber == 0)
                {
                    printf("你:剪刀 计算机:剪刀 平局~\n"); 
                }
                else if(userNumber == 1)
                {
                    printf("你:石头 计算机:剪刀 你胜利了!\n");
                }
                else if(userNumber == 2)
                {
                    printf("你:布 计算机:剪刀 很遗憾你输了~\n");
                }
                break;
            case 1:
                if(userNumber == 0)
                {
                    printf("你:剪刀 计算机:石头 很遗憾你输了~\n");
                }
                else if(userNumber == 1)
                {
                    printf("你:石头 计算机:石头 平局~\n");
                }
                else if(userNumber == 2)
                {
                    printf("你:布 计算机:石头 你胜利了!\n");
                }
                break;
            case 2:
                if(userNumber == 0) 
                {
                    printf("你:剪刀 计算机:布 你胜利了!\n");
                }
                else if(userNUmber == 1)
                {
                    printf("你:石头 计算机:布 很遗憾你输了~\n");
                }
                else if(userNumber == 2)
                {
                    printf("你:布 计算机:布 平局~\n");    
                } 
                break
        }
        printf("是否继续游戏(y/n?)");
        getcher();
        scanf("%c",&ch);
        if(cj==='y'||ch=='y')
             IsContine=true;
        else IsContine=false;
        }
        return 0;
}
 


运行结果及报错内容
3    19    C:\Users\HUAWEI\Desktop\8.c    [Error] cstdlib: No such file or directory
                                          compilation terminated.

我想要达到的结果

能跑出来

  • 写回答

1条回答 默认 最新

  • 关注

    代码修复后如下

    #include <stdio.h>
    #include <math.h>
    #include <cstdlib>
    #include <time.h>
    int main()
    {
        int computerNumber, userNumber;
        char ch = 'y';
        bool IsContine = true;
        while (IsContine)
        {
            srand(time(NULL));
            computerNumber = (int)(rand() % 3);
            printf("请输入用户你的选择:0-剪刀 1-石头 2-布\n");
            scanf("%d", &userNumber);
            switch (computerNumber)
            {
            case 0:
                if (userNumber == 0)
                {
                    printf("你:剪刀 计算机:剪刀 平局~\n");
                }
                else if (userNumber == 1)
                {
                    printf("你:石头 计算机:剪刀 你胜利了!\n");
                }
                else if (userNumber == 2)
                {
                    printf("你:布 计算机:剪刀 很遗憾你输了~\n");
                }
                break;
            case 1:
                if (userNumber == 0)
                {
                    printf("你:剪刀 计算机:石头 很遗憾你输了~\n");
                }
                else if (userNumber == 1)
                {
                    printf("你:石头 计算机:石头 平局~\n");
                }
                else if (userNumber == 2)
                {
                    printf("你:布 计算机:石头 你胜利了!\n");
                }
                break;
            case 2:
                if (userNumber == 0)
                {
                    printf("你:剪刀 计算机:布 你胜利了!\n");
                }
                else if (userNumber == 1)
                {
                    printf("你:石头 计算机:布 很遗憾你输了~\n");
                }
                else if (userNumber == 2)
                {
                    printf("你:布 计算机:布 平局~\n");
                }
                break;
            }
            printf("是否继续游戏(y/n?)");
            getchar();
            scanf("%c", &ch);
            if (ch == 'y' || ch == 'y')
                IsContine = true;
            else
                IsContine = false;
        }
        printf("20213002788张欣苗\n");
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月3日
  • 已采纳回答 11月25日
  • 修改了问题 11月25日
  • 修改了问题 11月25日
  • 展开全部

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?