Object
Write a program to interconvert the temperature scales using Menu options.
Algorithm
- Declare integer variable i and float variables c, f and k.
- Read i (consider i as switch variable).
- IF switch variable = 1
- Read c.
- Convert Celsius to Fahrenheit using f = 32+ (9/5) c.
- IF switch variable = 2
- Read f.
- Convert Fahrenheit to Celsius using c = (5/9)(f – 32)
- IF switch variable = 3
- Read c.
- Convert Celsius to Kelvin using k = c + 273.15.
- IF switch variable = 4
- Read f.
- Convert Fahrenheit to Kelvin using k = (5/9)(f – 32) + 273.15.
- ELSE
- Write Invalid switch variable.
- Exit.
Flowchart

C++ Source Code
// program 30
#include <iostream>
using namespace std;
int main()
{
int i;
float c, f, k;
cout << "\n\n\n";
cout << "\t\t\tMENU FOR TEMPERATURE SCALE CONVERSION";
cout << "\n\t\t\t_____________________________________\n\n";
cout << "1. From Celsius to Fahrenheit scale\n";
cout << "2. From Fahrenheit to Celsius scale\n";
cout << "3. From Celsius to Kelvin scale\n";
cout << "4. From Fahrenheit to Kelvin scale\n";
cout << "\nEnter the MENU option: ";
cin >> i;
switch (i)
{
case 1:
cout << "Enter temperature in Celsius: ";
cin >> c;
f = 32.0+(9.0/5.0)*c;
cout << "The temperature in Fahrenheit is = " << f;
break;
case 2:
cout << "Enter temperature in Fahrenheit: ";
cin >> f;
c = 5.0/9.0*(f-32.0);
cout << "The temperature in Celsius is = " << c;
break;
case 3:
cout << "Enter temperature in Celsius: ";
cin >> c;
k = c + 273.15;
cout << "The temperature in Kelvin is = " << k;
break;
case 4:
cout << "Enter temperature in Fahrenheit: ";
cin >> f;
k = (5.0/9.0*(f-32.0)) + 273.15;
cout << "The temperature in Kelvin is = " << k;
break;
default:
cout << "Invalid MENU option\n\n";
}
return 0;
}
C Source Code
/*program 30*/
#include<stdio.h>
int main()
{
int i;
float c, f, k;
printf("\n\n\n");
printf("\t\t\tMENU FOR TEMPERATURE SCALE CONVERSION");
printf("\n\t\t\t_____________________________________\n\n");
printf("1. From Celsius to Fahrenheit scale\n");
printf("2. From Fahrenheit to Celsius scale\n");
printf("3. From Celsius to Kelvin scale\n");
printf("4. From Fahrenheit to Kelvin scale\n");
printf("\nEnter the MEMU option: ");
scanf("%d", &i);
switch(i)
{
case 1:
printf("Enter temperature in Celsius: ");
scanf("%f", &c);
f = 32.0+(9.0/5.0)*c;
printf("The temperature in Fahrenheit is = %.2f", f);
break;
case 2:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = 5.0/9.0*(f-32.0);
printf("The temperature in Celsius is = %.2f", c);
break;
case 3:
printf("Enter temperature in Celsius: ");
scanf("%f", &c);
k = c + 273.15;
printf("The temperature in Kelvin is = %.2f", k);
break;
case 4:
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
k = (5.0/9.0*(f-32.0)) + 273.15;
printf("The temperature in Kelvin is = %.2f", k);
break;
default:
printf("Invalid MENU option\n\n");
}
return 0;
}
Output
MENU FOR TEMPERATURE SCALE CONVERSION
- From Celsius to Fahrenheit scale
- From Fahrenheit to Celsius scale
- From Celsius to Kelvin scale
- From Fahrenheit to Kelvin scale
Enter the MENU option: 2
Enter temperature in Fahrenheit: 145.3
The temperature in Celsius is = 62.9444
