Write a function named tempConvert that accepts a floating p

Write a function named tempConvert that accepts a floating point number representing a temperature and a character. If the character passed to the function is the letter f, the function should convert the passed temperature from Fahrenheit to Celsius; otherwise, of the character passed to the function is the letter c, the function should convert the passed temperature from Celsius to Fahrenheit. Test your function on the template provided.

Solution

#include <stdio.h>
float tempConvert (float ftemp, int ch){
if(ch == \'f\'){
return ((ftemp - 32) * 5)/9;
}
else{
return ftemp*(9/5) + 32;;
}
}
int main()
{
float t;
char ch;
printf(\"Enter the temperature: \");
scanf(\"%f\", &t);
printf(\"Enter the chracter (f or c): \");
scanf(\" %c\", &ch);
printf(\"Temperature is %f\ \", tempConvert(t,ch));
return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the temperature: 212                                                                                                                                                                                                                                             

Enter the chracter (f or c): f                                                                                                                                                                                                                                         

Temperature is 100.000000

Write a function named tempConvert that accepts a floating point number representing a temperature and a character. If the character passed to the function is t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site