C DEV-C + + loop with while

CSDN Q & A 2022-05-15 04:44:08 阅读数:878

dev-cdevloop

#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++;
}

}
After running, it is full 0, do not know why




Take the answer :

int a = scanf("number"); What the hell is it
if(z = a) This is supposed to be ==
This is a guessing game , The code is modified as follows :

#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;}

版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/131/202205041837280734.html