vendredi 29 septembre 2017

If/Else Statements in C are not working

Working on a basic computer science project for class and am stuck on this issue. I am experienced in Java but am just beginning in C language. It seems to simply skip over my if/else statement as if it were not there, could someone help me understand this?

#include <stdio.h>
int main()
{
        //Systems Programming: Project3 - Justus Milhon
        //Requests User Input
        printf("Enter temparature in Farenheit (int up to 3 digits): ");

        //Names and scans in Farenheit value
        float fare;
        scanf("%f", &fare);

        //Declares and calculates Celcius value
        float celc;
        celc = 5.0 / 9.0 * ( fare - 32 );

        //Determines approptiate description (if/else system)
        char desc[50] =  "if statement is not running :( "; 
        if(fare == -40){
            char desc[50] = "Ouch! Cold either way!!";
        }
        else if(fare == 32){
            char desc[50] = "Freezing point of water";
        }
        else if(fare == 70){
            char desc[50] = "Room temperature";
        }
        else if(fare == 99){
            char desc[50] = "Average body temperature";
        }
        else if(fare == 212){
            char desc[50] = "Boiling point of water";
        }
        else{
            char desc[50] = "final else stetement is being used :(";
        }

        //Prints output
        printf("Farenheit          Celsius          Description\n----------        
        ----------         ----------\n%.0f                 %.3f        
        %s\n", fare, celc, desc);
        return 0;
}

Aucun commentaire:

Enregistrer un commentaire