为什么我的if语句直接跳到其他

时间:2018-10-21 15:16:06

标签: c if-statement

我对C还是很陌生,所以很抱歉,如果这很简单或已经被回答,我收到的错误消息是“警告:如果(guess ==“ y”){“

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

int option;
char guess;

void new_game(){
    if (guess == "y") {
      if (rand() > 7){
        printf("You guessed right!");
      }
      else{
        printf("Wrong!   Try again");
      }
    }
    if (guess == "n") {
      if (rand() < 7){
        printf("You guessed right!");
      }
      else{
        printf("Wrong!   Try again");
      }
    }
    else{
    printf("Please enter either y or n");
    }
}


void main() {
srand(time(NULL));
    printf("Welcome To Higher Or Lower, choos an option from below!\n");
    printf("Press 1 for a new game\n");
    printf("Press 2 to view highscores\n");
    printf("Press 3 to quit\n");
    printf("Input here --> ");
    scanf(" %d", &option);
/*Option 1*/
    printf("Do you think the random number will be higher than 7\n");
    printf("Enter y for yes or n for no --> ");
    scanf(" %c", &guess);
    new_game();
}

0 个答案:

没有答案