m0_58683963 2022-05-04 18:27 采纳率: 100%
浏览 32
已结题

c dev-c++ 用while一直循环

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
int x = 1;
srand(time(0));
int y = rand();
int a = scanf("number");
int z = y%100;
printf("%d",z);
if(z = a){
printf("right%d",x);
}
while(z =! a){
printf("%d",a);
z = a;
x++;
}

}
运行后就是满篇的0,不知道为什么

  • 写回答

2条回答 默认 最新

  • qfl_sdu 2022-05-04 18:44
    关注

    int a = scanf("number");是什么鬼
    if(z = a)这里应该是==
    你这是猜数游戏吧,代码修改如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    
    int main(int argc, char* argv[]) {
        int x = 1;
        srand(time(0));
        int y = rand();
        printf("number");
        int a;
        scanf("%d",&a);
        int z = y % 100;
        //printf("%d", z);
        if (z == a) {
            printf("right%d", x);
        }
        while (z = !a) {
            scanf("%d", &a);
            //z = a;
            x++;
        }
        printf("%d", x);
        system("pause");
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月12日
  • 已采纳回答 5月4日
  • 创建了问题 5月4日

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)