Home > Enterprise >  Why is my yes(Y) not working but my no(N) working
Why is my yes(Y) not working but my no(N) working

Time:11-13

#include <stdio.h>

int main(){
    float fever ;

    printf("do you have fever? Enter Y or N: ");
    scanf("%f", &fever);
    
    if(fever =='y') {
        printf("you have symptom\n");
    } 
    else {
        printf("you dont have symptom\n");
    }

  return 0;
}

CodePudding user response:

The type of fever is not correct. It should be char as per your input.

#include <stdio.h>

int main(){
 char fever ;

 printf("do you have fever? Enter Y or N: ");
 scanf("%c", &fever);

 if(fever =='y' || fever == 'Y') {
     printf("you have symptom\n");
 } 
 else {
     printf("you dont have symptom\n");
 }

 return 0;
}

CodePudding user response:

instead of float fever use char or boolean type of variable, it's easier to use char here

#include <stdio.h>

int main(){
 char user_input ;

 printf("do you have fever? Enter Y or N: ");
 scanf("%c", &user_input);

 if(user_input =='y' || user_input == 'Y') {
     printf("you have symptom\n");
 } 
 else if(user_input == 'n' || user_input == 'N') {
     printf("you dont have symptom\n");
 }
 else {
     printf("please enter 'Y' or 'N'")
 }
 return 0;
}
  •  Tags:  
  • c
  • Related