Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- class Below_zero {};
- constexpr double ABSOLUTE_ZERO = 0;
- constexpr double ABS_ZERO_C = -273.15;
- double ctok(double c)
- {
- try{
- double k = c - ABS_ZERO_C;
- if (k < ABSOLUTE_ZERO)
- throw Below_zero{};
- return k;
- }
- }
- double ktoc(double k)
- {
- try{
- double c = k+ABS_ZERO_C;
- if (c < ABS_ZERO_C)
- throw Below_zero{};
- return c;
- }
- }
- int main()
- {
- while(cin){
- cout << "Please enter a number followed by C or K to denote Kelvin or Celsius, then press 'enter'\n";
- double b = 0;
- string u = "";
- cin >> b >> u;
- if (u == "c" || u == "C"){
- double r = ctok(b);
- u = " K";
- cout << r << u << '\n' ;
- //return 0;
- }
- else if (u == "k" || u == "K"){
- double r = ktoc(b);
- try{
- u = " C";
- cout << r << u << '\n';
- //return 0;
- }
- }
- else{
- error("invalid unit");
- return 2;
- }
- catch (Below_zero){
- cerr << "lower than absolute zero.\n";
- return 1;
- }
- }
- }
- merockstar@merockstar-HP-Pavilion-dv6-Notebook-PC:~/1CPPAttempt$ g++ -std=c++11 -Wall -Wextra -pedantic -O3 ch5ex2.cpp
- In file included from ch5ex2.cpp:1:0:
- std_lib_facilities.h: In member function ‘char& String::operator[](unsigned int)’:
- std_lib_facilities.h:107:9: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
- if (i<0||size()<=i) throw Range_error(i);
- ^
- std_lib_facilities.h: In member function ‘const char& String::operator[](unsigned int) const’:
- std_lib_facilities.h:113:9: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
- if (i<0||size()<=i) throw Range_error(i);
- ^
- ch5ex2.cpp: In function ‘double ctok(double)’:
- ch5ex2.cpp:16:1: error: expected ‘catch’ before ‘}’ token
- }
- ^
- ch5ex2.cpp:16:1: error: expected ‘(’ before ‘}’ token
- ch5ex2.cpp:16:1: error: expected type-specifier before ‘}’ token
- ch5ex2.cpp:16:1: error: expected ‘)’ before ‘}’ token
- ch5ex2.cpp:16:1: error: expected ‘{’ before ‘}’ token
- ch5ex2.cpp: In function ‘double ktoc(double)’:
- ch5ex2.cpp:28:1: error: expected ‘catch’ before ‘}’ token
- }
- ^
- ch5ex2.cpp:28:1: error: expected ‘(’ before ‘}’ token
- ch5ex2.cpp:28:1: error: expected type-specifier before ‘}’ token
- ch5ex2.cpp:28:1: error: expected ‘)’ before ‘}’ token
- ch5ex2.cpp:28:1: error: expected ‘{’ before ‘}’ token
- ch5ex2.cpp: In function ‘int main()’:
- ch5ex2.cpp:53:12: error: expected ‘catch’ before ‘}’ token
- }
- ^
- ch5ex2.cpp:53:12: error: expected ‘(’ before ‘}’ token
- ch5ex2.cpp:53:12: error: expected type-specifier before ‘}’ token
- ch5ex2.cpp:53:12: error: expected ‘)’ before ‘}’ token
- ch5ex2.cpp:53:12: error: expected ‘{’ before ‘}’ token
- ch5ex2.cpp:59:2: error: expected primary-expression before ‘catch’
- catch (Below_zero){
- ^
- ch5ex2.cpp:59:2: error: expected ‘;’ before ‘catch’
- merockstar@merockstar-HP-Pavilion-dv6-Notebook-PC:~/1CPPAttempt$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement