if (tanya == "y")
You do not need to use nor compare strings, when you only want to input a single character like y
or n
.
Instead use a char
object, input a character in it and compare if this character matches y
or Y
inside the condition of the if
statement:
printf(", Are you interested in Anime? (y/n)");
char tanya;
scanf("%c", &tanya);
if (tanya == 'y' || tanya == 'Y')
{....}
If you explicitly want to use strings, you need to compare two strings properly.
In C, one common way to compare two strings is by using the strcmp()
function in the header string.h
.
In your code it can be used as:
if(strcmp(tanya,"yes") == 0);
to accomplish the comparison and the proof of the if
statement to check if both strings are equal.
The whole code shall be like this:
#include <stdio.h>
#include <string.h>
char name[100],tanya[50],type[100];
int value;
int main()
{
printf("Enter name: ");
scanf("%s", name);
printf("Hello %s", name);
printf( ", Are you interested in Anime? (y/n)");
scanf("%s", tanya);
if(strcmp(tanya,"yes") == 0){
printf("Wow, you're an interesting person %s", tanya);
}
else{
printf("Good day sir.");
}
return 0;
}
By the way, it is kind of superficial to kick anybody just because he/she ain´t like animes ;-)