This:
if(fare == -40){
char desc[50] = "Ouch! Cold either way!!";
}
opens up a new scope, with a new local variable called desc
, that “shadows” the one in the surrounding scope. This variable is initialized to the string, then thrown away as the scope exits. The variable of the same name in the parent scope is never touched.
You need:
#include <string.h>
up top, and then change all the if
s to look like this:
if(fare == -40){
strcpy(desc, "Ouch! Cold either way!!");
}
This uses the standard strcpy()
function to write the new string into the single desc
variable in the parent scope.
Also you never look at celc
, which seems confusing after computing it, and exact comparisons of float
s is a bad idea.
7
solved If/Else Statements in C are not working