rand()方法在c中不起作用

时间:2017-09-23 09:06:13

标签: c

我正在构建一个基本的c程序,你猜测计算机生成的数字,我遇到的问题是数字总是83,我的代码在这里:

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

main() {
int number = rand() % 100;
int guesses = 0;
printf("You have 20 guesses to get the number \n");
while(guesses<50){
    int guess;
    scanf("%d", &guess);
    if(guess>50 && number>50){
        printf("Number is greater than 50! \n");
    }
    if(guess>75 && number>75){
        printf("Number is greater than 75! \n");
    }
    if(guess<50 && number<50){
        printf("Number is less than 50! \n");
    }
    if(guess<25 && number<25){
        printf("Number is less than 25! \n");
    }
    if(guess == number){
        printf("Well done you got the number! You guessed %d, it was %d \n", guess, number);
        exit(0);
    }
    guesses+=1;
}
}

0 个答案:

没有答案