#include #include // This method is not as good as the one in 1.cc because using modf // requires pointers, which haven't been covered yet and are easy // to get wrong. Using the example code from the math.h reference // should be okay though. long round(double x) { if (x < 0) { return -round(-x); } double intpart; double fractional = modf(x, &intpart); if (fractional >= 0.5) { return static_cast(ceil(x)); } else { return static_cast(floor(x)); } } int main() { double number; while (std::cin >> number) { std::cout << round(number) << std::endl; } }