In: Computer Science
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
// c++ program to find nearest integer of entered
decimal point number
#include <iostream>
using namespace std;
int round(double value); // function prototypes
int main()
{
double num;
int intnum;
cout << " Please enter number " ;
cin >> num;
// echo print the input
cout << " The number entered: " << num
;
// calculate and display the nearest
integer for each number
intnum = round(num);
cout << " The nearest integer: " <<
intnum;
}
// function round will round a floating point value to its nearest
integer value
int round(double value)
{
return int(value + 0.5);
}