mercredi 3 juin 2015

How to output only correct answer for temperature conversion?

A simple question but I have tried for a few hours and can't figure the last bit. How can I easily get program to display 'only' the correct answer Celsius or Farenheit, not both?

#include <stdio.h>
#include<conio.h>
int farenheit(int x);
int celcius(int x);
int main()
{
    int temperature,converted,converted2;
    int answer;
    printf("Temperature please\n");
    scanf("%d",&temperature);
    printf ("Enter conversion to be completed F/C\n");
    scanf ("%s",&answer);
    converted=farenheit(temperature);
    converted2=celcius(temperature);

    switch(answer)
{

    case 'f':converted;
    break;  

    case 'c':converted2;
    break;

}   
    getch ();
    return 0;
}
int farenheit(int x)
{
    int answer;
    answer= (x-32)*(float)5/9 ;
    printf ("Temperature in farenheit %d",answer);  
}
int celcius(int x)
{
    int ans;
    ans=((float)9/5*x)+32;
    printf ("Temperature in celcius %d",ans);
}

Aucun commentaire:

Enregistrer un commentaire