So after not coding in C for a while I wanted to make a simple test program where I would ask whether I liked a certain theme or not in Sublime Text
Here is the Code:
#include <stdio.h>
int main ( void ) {
char A [ 2 ];
printf ( "Do you like this theme? Answer Y or N: " );
scanf ( "%d", A );
if ( A == "Y" ) {
printf ( "Good.\n" );
} else {
printf ( "Why not?\n" );
}
return 0;
}
I write an if else statement in which I tell the program if the input is "Y" then print Good. Makes sense right, well every time I run the program it goes straight to the else statement which asks Why not?
Here is the output:
C:\Users\ \Desktop>a
Do you like this theme? Answer Y or N: Y
Why not?
C:\Users\ \Desktop>
Not sure what the issue is been looking for a way to fix it for a while not but nothings seems to work. Any help would be great. And if you know a place to learn C, rather than reading a book, that would be really helpful as well.
Aucun commentaire:
Enregistrer un commentaire