/* * ----------------------------------------------------- * CS2S03/SE2S03, September 2011 * Assignment 1, Question 3 * File: PE0109.cpp * ----------------------------------------------------- * This program rounds floating-point numbers to * integers * ----------------------------------------------------- */ #include "genlib.h" #include "simpio.h" #include #include /* Private function prototypes */ long Round(double x); /* Main program */ int main() { double x; cout << "Enter a real number: "; x = GetReal(); cout << "It is rounded to " << Round(x) << endl; return 0; } /* * Function: Round(double x) * Usage: rounded = Round(x); * ----------------------------------------------------- * This function rounds a floating-point number x to its * nearest integer; */ long Round(double x) { return (x > 0.0)? (long (x + 0.5)) : (long (x - 0.5)); }