(Rounding Numbers) An application of function floor is rounding a value to the nearest integer. The statement y = floor( x + .5 ); rounds the number x to the nearest integer and assigns 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 original number and the rounded number.
What will be an ideal response?
```
// Rounding numbers using floor.
#include
#include
#include
using namespace std;
double roundToIntegers( double ); // function prototype
int main()
{
double x; // current input
double y; // current input rounded
cout << fixed; // set floating-point number format
// loop for 5 inputs
for ( int loop = 1; loop <= 5; loop++ )
{
cout << "Enter a number: ";
cin >> x;
y = roundToIntegers( x ); // y holds rounded input
cout << setprecision( 6 ) << x << " rounded is "
<< setprecision( 1 ) << y << endl;
} // end for
} // end main
// roundToIntegers rounds 5 inputs
double roundToIntegers( double value )
{
return floor( value + .5 );
} // end function roundToIntegers
```
You might also like to view...
The new Photorealists of the 1980s were a direct response to color field painting, Minimalism, and conceptual art.
a. true b. false
If your browser doesn't support the pseudo-element to create a drop cap, you could use a(n) ____ element and apply your style to it to get the effect.
A. p B. div C. h1 D. span
Which of the following command can be used to remove a job from the list of pending jobs?
A. at --remove B. atrm C. at -r D. at -d
How does software differ from the artifacts produced by other engineering disciplines?
What will be an ideal response?