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日
  • 展开全部

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型