Question

In: Computer Science

LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...

LANGUAGE: C

Only using <stdio.h> & <stdlib.h>

Write a program that gives the user a 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 you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32

1. Use functions to accomplish 1 and 2 above.

2. Use at least one function for each scenario (i.e. converting temperature from degrees Fahrenheit to degrees Celsius and from degrees Celsius to degrees Fahrenheit). You must call them from the main function. You can use more functions if you see fit to do so, but use at least 4 functions.

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

Solutions

Expert Solution

Code:

#include<stdio.h> // header file which contains basic input output functions
#include<stdlib.h> // header file for general purpose standard library
int cal_temp_cel(); //function declaration
int cal_cel_temp(int tem1); //function declaration
int cal_temp_far(); //function declaration
int cal_far_temp(int tem3); //function declaration
int display_menu(); //function declaration
int main() //main function
{
int ch,tem1,tem2,tem3,tem4,flag=0; // variable declaration and initialization
  
while(flag!=3) // the loop will run till the value of flag becomes 3
{
ch=display_menu(); //function call to display the menu
switch(ch) //input for menu
{
case 1:
tem1=cal_temp_cel(); //function call to enter the value
tem2=cal_cel_temp(tem1); //function call to calculate the value
printf("%d degree F = %d degree C \n",tem1,tem2); //display the final result
break;
  
case 2:
tem3=cal_temp_far(); //function call to enter the value
tem4=cal_far_temp(tem3); //function call to calculate the value
printf("%d degree C = %d degree F \n",tem3,tem4); //display the final result
break;
  
case 3:
exit(0);
  
default:
printf("Please Enter a valid Choice! \n"); // to handle invalid choices
exit(0);
  
}
}
return 0;
}
int display_menu() // menu
{
int choice;
printf("1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius \n");
printf("2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit \n");
printf("3. Quit \n");
printf("Enter Your Choice: ");
scanf("%d",&choice);
return choice;
}
int cal_temp_cel() //function to take the input for Fahrenheit
{
int far;
printf("Enter the value in Fahrenheit Scale: ");
scanf("%d",&far);
return far;
}
int cal_cel_temp(int tem1) //function to calculate the value in celcius
{
int c;
c=(tem1-32)*5/9; //formula
return c;
}
int cal_temp_far() //function to take the input for celcius
{
int cel;
printf("Enter the value in Celsius Scale: ");
scanf("%d",&cel);
return cel;
}
int cal_far_temp(int tem3) //function to calculate the value in Fahrenheit
{
int f;
f=(tem3*9/5)+32; //formula
return f;
}

For your reference

Code:

Output:


Related Solutions

C language <stdio.h> use double and const Write a program that asks the user for the...
C language <stdio.h> use double and const Write a program that asks the user for the radius of a circle (as a double) and displays the diameter, circumference, and area of the circle. Use a constant of 3.14159 as the value of pi. Have a blank line between the input and the output. Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. The formulas needed are: diameter = 2 * radius circumference = 2 *...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:    F = (9 / 5) * C + 32 Create integer constants for the 3 numbers in the formula (9, 5, and 32).  Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void...
Write the below C program using ARM assembly language and compile for Cortex A53. #include<stdio.h> void quicksort(int number[25],int first,int last){ int i, j, pivot, temp; if(first<last) { pivot=first; i=first; j=last; while(i<j) { while(number[i]<=number[pivot]&&i<last) i++; while(number[j]>number[pivot]) j--; if(i<j){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } temp=number[pivot]; number[pivot]=number[j]; number[j]=temp; quicksort(number,first,j-1); quicksort(number,j+1,last); } } int main() { int i, count, number[25]; printf("Enter some elements (Maximum 25): "); scanf("%d",&count); printf("Enter %d elements: ", count); for(i=0;i<count;i++) scanf("%d",&number[i]); quicksort(number,0,count-1); printf("The Sorted Order is: "); for(i=0;i<count;i++) printf(" %d",number[i]); return...
A. Write a C++ with a menu (using switch) that asks the user to select one...
A. Write a C++ with a menu (using switch) that asks the user to select one of the following choices to the user: 1. Options ‘S’ or ‘s’ 2. Option ‘T’ or ‘t 3. Options ‘P’ or ‘p’ 4. print in the Matrix format B. When 1 is selected, prompt the user to enter the starting value st (int value). Use a single FOR loop to count numbers from 1 to st. When the loop is finished, find the average...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT