[Solved]Write C Program Using Functions According Assignment Must Write Code C Using Functions Ex Q37223959
I have to write a C program using Functions, accordingto the assignment below.
“You must write the code in C using functions as explainedbelow. This is a requirement for this assignment. You will earn agrade of zero if you do not demonstrate the use of functions to dothis assignment.
Write a program that gives user following menu to choose from–
- Option 1: Convert temperature input from the user in degreesFahrenheit to degrees Celsius.
- Option 2: Convert temperature input from the user in degreesCelsius to degrees Fahrenheit. Use the following functions:
C = (5.0 / 9) * (F-32)
F = (9.0 / 5) * C + 32
- Option 3: Quit.
This menu should be shown again and again till user chooses toselect option 3. (hint – use ‘do..while’ loop)
Specifications:
- Option 1 – must use the following functions:
- A function that gets the user input in degrees Fahrenheit.
- A function that converts the degrees Fahrenheit temperature todegrees Celsius.
- A function that displays the converted temperature.
- Option 2 – must use the following functions:
- A function that gets the user input in degrees CelsiusFahrenheit.
- A function that converts the degrees Celsius temperature todegrees Fahrenheit.
- A function that displays the converted temperature.
Write additional functions to make the menu work correctly. Theonly code that should be written inside the main function is thevariable declarations and function call/s. Do remember that you cancall one function inside another function, if needed.”
I thought I did it correctly, but upon submission myprofessor indicated that the “main function cannot have any codeother than function calls and variable declarations.” The code Ihave thus far, which runs successfully, is postedbelow:
// Alexandra Valladares
// 19 April 2019
// Assignment 9: Program that converts temperature inputfrom user from Fahrenheit to Celsius and/or from Celsius toFahrenheit
#include<stdio.h>
#include<stdlib.h>
// function to convert temperature input from Celsius toFahrenheit
int CtoF(int n) {
return (9 * n) / 5+ 32;
}
// function to convert temperature input from Fahrenheitto Celsius
int FtoC(int n) {
return (5 * (n -32)) / 9;
}
// main function
int main() {
intop,n;
// menudisplay
while (1){
printf(“1. Convert temperature input from the user in degreesFahrenheit to degrees Celsius.n”);
printf(“2. Convert temperature input from the user in degreesCelsius to degrees Fahrenheit.n”);
printf(“3. Quit.n”);
scanf_s(“%d”, &op);
// switching to option
switch (op) {
//case 1 – Fahrenheit to Celsius conversion
case 1:
printf(“Enter the temperature in degreesFahrenheit:”);
scanf_s(“%d”, &n);
printf(“%d degrees Fahrenheit = %d degrees Celsiusn”, n,FtoC(n));
break;
//case 2 – Celsius to Fahrenheit Conversion
case 2:
printf(“Enter the temperature in Celsius:”);
scanf_s(“%d”, &n);
printf(“%d degrees Celsius = %d degrees Fahrenheitn”, n,CtoF(n));
break;
//case 3 – Quit
case 3:
printf(“Exiting the Program. Thank you!n”);
exit(0);
break;
}
}
return0;
}
// end of the Program
Expert Answer
Answer to I have to write a C program using Functions, according to the assignment below. “You must write the code in C using func… . . .
OR

