// Mr. Minich
// CMPSC 101
// Ch. 1 Demo Program #6
// January 30, 2000 
// Purpose - a rounding algorithm that uses type casting

#include <iostream>
#include <cmath> using namespace std; int main() { double num = 0.0; double roundedNum = 0.0; cout << "Enter a number with more than 2 decimal places: "; cin >> num; roundedNum = (static_cast <int> ((num * 100) + 0.5))/ 100.0; // or // roundedNum = (int ((num * 100) + 0.5))/ 100.0; using old-fashioned type casting // or // roundedNum = (floor ((num * 100) + 0.5))/ 100.0; using the floor library function // from cmath or math.h which must be // included at the top of the program cout << num << " rounded to the nearest hundredth's is " << roundedNum << endl; return 0; }
//end of main