#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,不知道为什么
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;
}
第一处是int a=scanf处,有问题,不能这么写,第二处,if后面z==a,第三处,while后面z!=a