//header #include #include #include //declared - TopicsExpress



          

//header #include #include #include //declared variables float Fahrenheit; float Celsius; //function to convert Celsius To Fahrenheit float CelsiusToFahrenheit(float Celsius) { return (5.0/9.0 * (Fahrenheit-32)); } //function to convert Fahrenheit To Celsius float FahrenheitToCelsius(float Fahrenheit) { return (9.0/5.0 * (Celsius+32); } //main start int main() { char choice; float temperature; //program header printf(*Program for Temperature Conversion*\n); printf(This program converts temperature from Fahrenheit to Celsius and from Celsius to Fahrenheit); //ask users choice printf(\n\nEnter (1) for Fahrenheit to Celsius and (2) for Celsius to Fahrenheit : ); scanf(%c,&choice); //check if user has pressed a digit if(isdigit(choice)) { if(choice==1) //if choice is 1 i.e., Fahrenheit to Celsius { //input temperature in Fahrenheit printf(\nEnter temperature in Fahrenheit : ); scanf(%f,&temperature); //display result printf(\nThe temperature %.2f Fahrenheit is %.2f Celsius. \n, temperature, FahrenheitToCelsius(temperature)); } else if(choice==2) //if chocie is 2 i.e., Celsius to Fahrenheit { //input temperature in Celsius printf(\nEnter temperature in Celsius : ); scanf(%f,&temperature); //display result printf(\nThe %.2f Celsius is %.2f Fahrenheit. \n, temperature, CelsiusToFahrenheit(temperature)); } else //if input is wrong printf(NO! I said choose 1 or 2!); } else //if user has pressed invalid character printf(I said 1 or 2!); //hold output screen system(pause); return 0; }
Posted on: Sat, 19 Oct 2013 23:23:00 +0000

Trending Topics



Recently Viewed Topics




© 2015