Hello,
This is a new post, and I am relatively new to the XCode IDE. Listed below is a snippet of code, using string (char) constants along with if...else statements. The code speaks for itself, but obviously does not work the intended way.
Meaning, no matter if you enter "Celcius" or "Fahrenheit", the conditional always defaults to "neither." I'm guessing the code if <some condition> == <some string or char statement> is not being equated or compiled properly, so any info is appreciated. Thanks.
fjm
#include <stdio.h>
int main (int argc, const char * argv[]) { char scale[12];
printf ("Enter the temperature scale you're coming from, either Celcius or fahrenheit.\n"); scanf ("%s", &scale);
printf ("%s\n", scale);
if (scale == "Celcius") { printf ("You're in the Celcius scale.\n"); } else if (scale == "Fahrenheit") { printf ("You're in the Fahrenheit scale.\n"); } else printf ("Looks like you're in neither.\n"); return 0; } |