-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchap5e2.cpp
61 lines (50 loc) · 1.02 KB
/
chap5e2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* =====================================================================================
*
* Filename: chap5e2.cpp
*
* Description:
*
* Version::q! 1.0
* Created: 02/14/2021 10:04:40 AM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "std_lib_facilities.h"
double ctok(double c)
{
if(c < -273.15) error("Temperature can not be reached beyond this!");
double k = c+273.15;
return k;
}
double ktoc(double k)
{
if(k<0) error("temperature can't reach to that point");
double c = k-273.15;
return c;
}
int main()
{
try{
double t =0;
string u=" ";
cin>>t>>u;
if(u=="c" || u=="celsius"){
double r_t = ctok(t);
cout<<r_t<<" Kelvin";
}
if(u=="k" || u=="kelvin"){
double r_t = ktoc(t);
cout<<r_t<<" Celsius";
}
return 0;
}
catch(runtime_error& e){
cerr<<"runtime_error: "<<e.what()<<'\n';
}
}