15.Create a program in C to convert temperature from Celsius to Fahrenheit or vice versa using switch case.
Purpose:
The purpose of this program is to provide a user-friendly tool for converting temperatures between Celsius and Fahrenheit scales. By utilizing a 'switch-case' statement, the program allows users to easily select the conversion they desire and obtain the corresponding result.
Agenda:
1. Display a menu to the user with options for temperature conversion: Celsius to Fahrenheit or Fahrenheit to Celsius.
2. Prompt the user to enter the temperature value they want to convert.
3. Based on the user's selection, use a 'switch-case' statement to perform the appropriate temperature conversion calculation.
4. Display the converted temperature value to the user.
5. Allow the user to perform additional conversions or exit the program based on their choice.
Real-life applications:
1. Weather forecasting systems: Weather applications often need to convert temperature readings between Celsius and Fahrenheit for user-friendly display and comparison.
2. Cooking and baking: Recipes from different sources may use either Celsius or Fahrenheit, so a conversion program can help chefs and bakers follow recipes accurately.
3. HVAC systems: Heating, ventilation, and air conditioning systems may require temperature conversions for setting and adjusting room temperatures.
4. Medical applications: Medical devices and healthcare professionals may need to convert temperature measurements between Celsius and Fahrenheit for patient monitoring and treatment.
a program in C to convert temperature from Celsius to Fahrenheit or vice versa using switch case.
/* C language program to convert temperature from Celsius
to Fahrenheit or vice versa using switch case.*/
#include <stdio.h>
int main()
{
int choice;
float temperature, convertedTemp;
printf("Enter 1 to convert from Celsius to Fahrenheit\n");
printf("Enter 2 to convert from Fahrenheit to Celsius\n");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("Enter temperature in Celsius: ");
scanf("%f", &temperature);
convertedTemp = (temperature * 9/5) + 32;
printf("Temperature in Fahrenheit: %.2f\n", convertedTemp);
break;
case 2:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &temperature);
convertedTemp = (temperature - 32) * 5/9;
printf("Temperature in Celsius: %.2f\n", convertedTemp);
break;
default:
printf("Invalid choice. Please enter either 1 or 2.\n");
}
return 0;
}