fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::min;
  7. using std::max;
  8.  
  9. //returns true if the variance is less than 0.01
  10. bool valuesAreSimilar(double a, double b) {
  11. return std::abs(a - b) < 0.01;
  12. }
  13.  
  14. int main()
  15. {
  16. double value02;
  17. double value01;
  18.  
  19. while (cin >> value01 >> value02) {
  20. if (value01 != value02) {
  21. cout << "The smaller value is: " << min(value01, value02)
  22. << " , the larger value is: " << max(value01, value02) << "\n";
  23. if (valuesAreSimilar(value01, value02)) {
  24. cout << "The numbers are almost equal. \n";
  25. }
  26. }
  27. else {
  28. cout << "Both of these numbers are equal!" << "\n";
  29. }
  30. }
  31. cout << "Not a value I know! Incorrect input" << "\n";
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'bool valuesAreSimilar(double, double)':
prog.cpp:11:24: error: call of overloaded 'abs(double)' is ambiguous
   return std::abs(a - b) < 0.01;
                        ^
In file included from /usr/include/c++/5/cstdlib:72:0,
                 from /usr/include/c++/5/bits/stl_algo.h:59,
                 from /usr/include/c++/5/algorithm:62,
                 from prog.cpp:2:
/usr/include/stdlib.h:775:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
In file included from /usr/include/c++/5/bits/stl_algo.h:59:0,
                 from /usr/include/c++/5/algorithm:62,
                 from prog.cpp:2:
/usr/include/c++/5/cstdlib:166:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
/usr/include/c++/5/cstdlib:174:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
stdout
Standard output is empty