CEZJ_ 2022-11-02 17:43 采纳率: 71.4%
浏览 30
已结题

一个简单的随机数游戏

问题遇到的现象和发生背景 游戏目的是:电脑随机生成一个数,然后玩家输入一个数,看几次可以相同。我想要做到一个人重复四次游戏,且一次游戏里一直猜测直到相同。
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    srand((unsigned int)time(NULL)*10);
    int num1 = rand() %32 + 1;
    int num2;
    int cs = 0;
    int game = 0;
    int best;
    int last;
    if (game < 4)
    {printf("Please enter a number in 1-32, which you think is the same with computer:\n");
     scanf("%d",&num2);
     if (num1 == num2)
     {
        cs++;
        printf("You are correct!\n");
     }
     else
     {
        cs++;
        printf("You are wrong!Try again.\n");
        do{
             printf("Please enter a number, which you think is the same with computer:\n");
             scanf("%d",&num2);
             printf("You are wrong again!");
             cs++;
        } while(num1 == num2);
       
      } 
         printf("Your grades is %d.\n",cs);
        printf("Write down your last time best grade :");
        scanf("%d",&last);
        if (cs < last)
        {
            best = cs;
            printf("Your best score now is %d.",best);
        }
        else
        {
            best = last;
            printf("Your best score now is %d.",best);
        }
     }
     else
     {
        printf("You have finished this game now!\n Here is your best grade:%d.\n",best);
     }
     

    
    return 0;

}

运行结果及报错内容 玩家输入两次后就结束了,没有一直在循环里,不知道为什么
我的解答思路和尝试过的方法
我想要达到的结果 玩家一直循环,直到猜中当局随机数
  • 写回答

3条回答 默认 最新

  • 叶落花枯 2022-11-02 17:50
    关注

    31行,num1 != num2
    不等于就继续循环,等于就退出

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月10日
  • 已采纳回答 11月2日
  • 创建了问题 11月2日

悬赏问题

  • ¥15 使用yolov5-7.0目标检测报错
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备