-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemperatureConverter.cpp
46 lines (44 loc) · 1.22 KB
/
TemperatureConverter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
double celsius_to_fahrenheit(double celsius){
return (celsius * 9/5) + 32;
}
void convertCelsiusToFahrenheit() {
double celsius;
cout<<"Enter value in Celsius : ";
cin>>celsius;
double fahrenheit = celsius_to_fahrenheit(celsius);
cout<<celsius<<" Celsius is "<<fahrenheit<<" Fahrenheit."<<endl;
};
double fahrenheit_to_celsius(double fahrenheit){
return (fahrenheit - 32) * 5/9;
}
void convertFahrenheitToCelsius(){
double fahrenheit;
cout<<"Enter value in Fahrenheit : ";
cin>>fahrenheit;
double celsius = fahrenheit_to_celsius(fahrenheit);
cout<<fahrenheit<<" Fahrenheit is "<<celsius<<" Celsius."<<endl;
};
int main() {
int choice;
cout<<"Temperature converter Menu : "<<endl;
cout<<"1. Celsius to Fahrenheit. "<<endl;
cout<<"2. Fahrenheit to Celsius. "<<endl;
while (1) {
cout<<"Enter choice : ";
cin >> choice;
switch (choice) {
case 1:
convertCelsiusToFahrenheit();
break;
case 2:
convertFahrenheitToCelsius();
break;
default:
cout << "Invalid choice." << endl;
break;
}
}
return 0;
}