Advertisement
xerpi

rounding c++

Sep 15th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     double x;
  6.     cin >> x;
  7.    
  8.     if(x == 0.0) {
  9.         cout << "0 0 0";
  10.     }
  11.     else {
  12.         int floor = int(x);
  13.        
  14.         double decimal = x - double(floor);
  15.         cout << floor << " ";
  16.        
  17.         //Integer number
  18.         if(x == double(floor))
  19.             cout << floor << " ";
  20.         else
  21.             cout << floor+1 << " ";
  22.        
  23.         //Rounding
  24.         if (decimal >= 0.5)
  25.             cout << floor +1;
  26.         else
  27.             cout << floor;
  28.     }
  29.     cout << endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement