Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. #include "std_lib_facilities.h"
  2.  
  3. class Below_zero {};
  4. constexpr double ABSOLUTE_ZERO = 0;
  5. constexpr double ABS_ZERO_C = -273.15;
  6.  
  7. double ctok(double c)
  8. {
  9. try{
  10. double k = c - ABS_ZERO_C;
  11. if (k < ABSOLUTE_ZERO)
  12. throw Below_zero{};
  13. return k;
  14. }
  15.  
  16. }
  17.  
  18. double ktoc(double k)
  19. {
  20. try{
  21. double c = k+ABS_ZERO_C;
  22. if (c < ABS_ZERO_C)
  23. throw Below_zero{};
  24.  
  25. return c;
  26. }
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32.  
  33. while(cin){
  34.  
  35. cout << "Please enter a number followed by C or K to denote Kelvin or Celsius, then press 'enter'\n";
  36.  
  37. double b = 0;
  38. string u = "";
  39. cin >> b >> u;
  40. if (u == "c" || u == "C"){
  41. double r = ctok(b);
  42. u = " K";
  43. cout << r << u << '\n' ;
  44. //return 0;
  45. }
  46. else if (u == "k" || u == "K"){
  47. double r = ktoc(b);
  48. try{
  49. u = " C";
  50. cout << r << u << '\n';
  51. //return 0;
  52. }
  53. }
  54. else{
  55. error("invalid unit");
  56. return 2;
  57. }
  58.  
  59. catch (Below_zero){
  60. cerr << "lower than absolute zero.\n";
  61. return 1;
  62. }
  63. }
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. merockstar@merockstar-HP-Pavilion-dv6-Notebook-PC:~/1CPPAttempt$ g++ -std=c++11 -Wall -Wextra -pedantic -O3 ch5ex2.cpp
  73. In file included from ch5ex2.cpp:1:0:
  74. std_lib_facilities.h: In member function ‘char& String::operator[](unsigned int)’:
  75. std_lib_facilities.h:107:9: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
  76. if (i<0||size()<=i) throw Range_error(i);
  77. ^
  78. std_lib_facilities.h: In member function ‘const char& String::operator[](unsigned int) const’:
  79. std_lib_facilities.h:113:9: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
  80. if (i<0||size()<=i) throw Range_error(i);
  81. ^
  82. ch5ex2.cpp: In function ‘double ctok(double)’:
  83. ch5ex2.cpp:16:1: error: expected ‘catch’ before ‘}’ token
  84. }
  85. ^
  86. ch5ex2.cpp:16:1: error: expected ‘(’ before ‘}’ token
  87. ch5ex2.cpp:16:1: error: expected type-specifier before ‘}’ token
  88. ch5ex2.cpp:16:1: error: expected ‘)’ before ‘}’ token
  89. ch5ex2.cpp:16:1: error: expected ‘{’ before ‘}’ token
  90. ch5ex2.cpp: In function ‘double ktoc(double)’:
  91. ch5ex2.cpp:28:1: error: expected ‘catch’ before ‘}’ token
  92. }
  93. ^
  94. ch5ex2.cpp:28:1: error: expected ‘(’ before ‘}’ token
  95. ch5ex2.cpp:28:1: error: expected type-specifier before ‘}’ token
  96. ch5ex2.cpp:28:1: error: expected ‘)’ before ‘}’ token
  97. ch5ex2.cpp:28:1: error: expected ‘{’ before ‘}’ token
  98. ch5ex2.cpp: In function ‘int main()’:
  99. ch5ex2.cpp:53:12: error: expected ‘catch’ before ‘}’ token
  100. }
  101. ^
  102. ch5ex2.cpp:53:12: error: expected ‘(’ before ‘}’ token
  103. ch5ex2.cpp:53:12: error: expected type-specifier before ‘}’ token
  104. ch5ex2.cpp:53:12: error: expected ‘)’ before ‘}’ token
  105. ch5ex2.cpp:53:12: error: expected ‘{’ before ‘}’ token
  106. ch5ex2.cpp:59:2: error: expected primary-expression before ‘catch’
  107. catch (Below_zero){
  108. ^
  109. ch5ex2.cpp:59:2: error: expected ‘;’ before ‘catch’
  110. merockstar@merockstar-HP-Pavilion-dv6-Notebook-PC:~/1CPPAttempt$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement