// Mr. Minich // Computer Science Using C++ // Ch. 5 Demo Program #8 // January 30, 2000 // purpose - The program illustrates a simple algorithm for rounding to a decimal place. #include<iostream.h> #include <iomanip.h> #include <math.h> int main() { double userNum = 0.0; int userPlace = 0; int tensFactor = 0; double roundedNum = 0.0; cout << "Enter a decimal number: "; cin >> userNum; cout << "Enter the desired number of decimal places: "; cin >> userPlace; tensFactor = pow(10, userPlace); cout.setf(ios::fixed); roundedNum = double (int (userNum * tensFactor + 0.5)) / tensFactor; cout << setprecision(userPlace) << roundedNum << endl; return 0; } // end of main