samedi 7 novembre 2015

Converting temperatures from Celsius to Fahrenheit

I wrote a program that converts temperatures from Celsius to Fahrenheit, when i enter (c) the syntax works so good , but when i enter f it gave me a random numbers :::

#include <stdio.h>

int main (void){
    float f,c;

    printf("x=Ende c=Umrechnung c->f f=Umrechnung f->c:");
    if(scanf("c",&c)==c){
        printf("Grad Celisius =");
        scanf("%f",&c);
        f=(c*1.8)+32;
        printf("%.2f Grad Celisius sind %.2f Grad Fahreiheit\n",c,f);
    }
    else if(scanf("f",&f)==f){
        printf("Grad fahrenheit =");
        scanf("%f",&f);
        c=(f-32)/1.8;
        printf("%.2f Grad Fahrenheit sind %.2f Grad Fahrenheit",f,c);
    }
    return 0;
}

How can I fix my problem?

Aucun commentaire:

Enregistrer un commentaire