I'm not having any luck with my IF statement. I've tried changing around the variables, etc, but I'm not sure why it won't work. It does compile, but the output is always 0. I don't know why. I'm using a %d placeholder for the wind = variable. I think that C treats characters as int, so I should be able to use the %d placeholder for text, right? Any ideas? I have already written a similar program, that worked, but I don't see the difference. So I'm at a loss on this one.
Code:
#include <stdio.h>
main ()
{
int velocity, wind ;
int calm, light, breezy, gale, storm, hurricane;
printf ("Enter wind velocity (knots): ") ;
scanf ("%d", &velocity ) ;
if (velocity < 1 )
wind = calm ;
else if (velocity < 4 )
wind = light ;
else if (wind < 28 )
wind = breezy ;
else if (velocity < 48 )
wind = gale ;
else if (velocity < 64 )
wind = storm ;
else if (velocity > 63 )
wind = hurricane ;
printf ("Conditions are... %d\n", wind) ;
return ;
}
Code:
Light airScott-Deans-MacBook-Pro:~ scottdean$ gcc ~/documents/wind.c
Scott-Deans-MacBook-Pro:~ scottdean$ ./a.out
Enter wind velocity (knots): 2
Conditions are... 0