CEZJ_ 2022-11-01 18:45 采纳率: 71.4%
浏览 21
已结题

一个简单的随机数问题

问题遇到的现象和发生背景 随机数num1,一直与输入的num2相同
用代码块功能插入代码,请勿粘贴截图 #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;
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.");
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);
do{
printf("Let us try again! You have got a lot of mistakes.");
cs=0;
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);

    } while(cs < 4);
}
printf("Your grades is %d.",cs);
return 0;

}

我想要达到的结果 一个简单的游戏,看你的输入次数,输入几次与产生的随机数相同,超过四次就重新一局游戏
  • 写回答

3条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-11-01 18:49
    关注

    if (num1 == num2) 两个等号才是比较,一个等号只是赋值,赋值语句为真就走if里边了

    img

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

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line