// Problem 3.13 // An application of function floor is rounding a value to the nearset integer. // The statement // y=floor(x+.5); // will round the number x to the nearset integer and assign the result to y. // Write a program that reads several numbers and uses the preceding statement // to round each of these numbers to the nearest integer. For each number // processed, print both the orignal number and the rounded number. // #include #include #include // GRADER: There are many ways to demonstrate this problem. Be flexible! float roundToInteger( float ); main() { float x,y; cout << setiosflags( ios::fixed | ios::showpoint ) << setprecision(4) << endl; for( int i=0; i<=5; i++) { cout << "Enter a floating point value: "; cin >> x; y = roundToInteger( x ); cout << x << " rounded is " << y << endl; } return 0; } float roundToInteger( float a ) { double b; b = floor( a + 0.5 ); return b; }