Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAMMING LANGUAGE Write a program to converts temperatures between Fahrenhe

ID: 3690744 • Letter: C

Question

C PROGRAMMING LANGUAGE

Write a program to converts temperatures between Fahrenheit and Celsius. Your program should print a brief message describing what it does, and then prompt the user to enter "1" if they would like to convert a Fahrenheit number to Celsius, or "2" to convert a Celsius number to Fahrenheit. Then, allow the user to enter the number to be converted. Your program should call a function to perform the conversion and display the resulting value to the screen. C= (5.0/9.0 * (F-32)); C = temperature in degrees Celsius, F = temperature in degrees Fahrenheit F= (9.0/5.0 * C+32); C = temperature in degrees Celsius, F = temperature in degrees Fahrenheit When you integer division, the result is always an integer so all decimal numbers are truncated and not rounded. For example, 5/6=0 when it comes to integers. Keep this in mind when doing your conversions. Also, order of operations count! Include a flowchart for your program. Be sure that you create a separate flowchart diagram for each function - In this case, you should have three flowchart diagrams. Your program must have two separate conversion functions: one to convert Fahrenheit to Celsius and one to convert Celsius to Fahrenheit. Your program must be well documented (ie use comments!) Your program should be user friendly. That means it should handle incorrect user input and output should be labeled (Don't just print the number; display a clear message, such as "The temperature in Celsius is 45")

Explanation / Answer

#include <stdio.h>
//Function to convert Fahrenheit to Celcius
void F2C(float F){
float C = 5.0/ 9.0 * (F-32);
printf("The %f degree Fahrenheit temperature in degree Celcius is %f",F,C);
}
//Function to convert Celcius to Fahrenheit
void C2F(float C){
float F = 9.0/ 5.0 * C + 32;
printf("The %f degree Celcius temperature in degree Fahrenheit is %f",C,F);
}
//Main function
int main(void) {
int opt;
float value;
printf("Enter 1. to convert degree Fahrenheit to degree Celcius ");
printf("Enter 2. to convert degree Celcius to degree Fahrenheit ");
scanf("%d",&opt);
printf("Enter the value to be converted : ");
scanf("%f",&value);
//Checking for F2C or C2F
if(opt == 1)
F2C(value);
else if(opt==2)
C2F(value);
else
printf("Invalid Option");
   return 0;
}