C++ program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer
Posted by Samath
Last Updated: April 06, 2022

Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.


Code:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  double num;

  cout << "Please enter a decimal number: ";
  cin >> num;


  cout << "Result: ";
  cout << setprecision(0) << num << endl;

  return 0;
}