Write the code using functions. Write a C program that gives user menu to choose
ID: 3771193 • Letter: W
Question
Write the code using functions. Write a C program that gives user menu to choose from –
1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius
2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit
3. Quit.
Formulae- C = (5 / 9) * (F-32) and F = (9/5) * C + 32
Need to use functions only to accomplish 1 and 2.
Need to use at least two functions for each scenario and need to call them from the main function. Can use more functions as you see fit.
Test the program with the following values:
68 degree F = 20 degree C
20 degree C = 68 degree F
-22 degree F = -30 degree C
0 degree C = 32 degree F
Explanation / Answer
#include<stdio.h>
int CtoF(int n){
return (9 * n ) /5 +32;
}
int FtoC(int n){
return (5 * (n-32) /9);
}
int main(){
int op,n;
while(1){
printf("1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius ");
printf("2.Convert temperature input from the user in degrees Celsius to degrees Fahrenheit ");
printf("3.Quit ");
scanf("%d",&op);
switch (op){
case 1:
printf("Enter F");
scanf("%d",&n);
printf("%d F is converted to %d C ",n,FtoC(n));
break;
case 2:
printf("Enter C");
scanf("%d",&n);
printf("%d C is converted to %d F ",n,CtoF(n));
break;
case 3:
exit(0);
break;
default : printf("Wrong option , Please re-enter ");
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.