-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02.3 (C++) Convert Celsius vs Kelvin using switch statement.cpp
More file actions
75 lines (53 loc) · 1.56 KB
/
02.3 (C++) Convert Celsius vs Kelvin using switch statement.cpp
File metadata and controls
75 lines (53 loc) · 1.56 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/// Convert between Celsius and Kelvin by using switch statement
#include <iostream>
using namespace std;
int main()
{
double celsius, kelvin;
int n;
while(1)
{
cout<<endl<<endl;
cout<<" Press 1: Kelvin to Celsius"<<endl;
cout<<" Press 2: Celsius to Kelvin"<<endl;
cout<<" Enter your choice: ";
cin>>n;
switch(n)
{
case 1:
cout<<" Enter Kelvin: ";
cin>>kelvin;
celsius = kelvin - 273;
cout<<" Celsius: "<<celsius<<endl;
break;
case 2:
cout<<" Enter Celsius: ";
cin>>celsius;
kelvin = celsius + 273;
cout<<" Kelvin: "<<kelvin<<endl;
break;
default:
cout<<" Choice any option!"<<endl;
break;
}
}
return 0;
}
/* ===== Output/Result:
--------------- 1st Choice:
Input:___________________
Press 1: Kelvin to Celsius
Press 2: Celsius to Kelvin
Enter your choice: 1
Enter Kelvin: 22
Output:_________________
Celsius: -251
--------------- 2nd Choice:
Input:___________________
Press 1: Kelvin to Celsius
Press 2: Celsius to Kelvin
Enter your choice: 2
Enter Celsius: 31
Output:_________________
Kelvin: 304
*/