When testing the program the result was obtained:
Input - value
9.995 - 9.99 (instead of 10.00)
0.995 - 1.00
152.995 - 153.0
7.895 - 7.89 (instead of 7.90)
The following is the source code of the program:
1st file
int main() { setlocale(LC_ALL, "Russian"); double n,rub,cop; cout << "Преобразование числа в денежный формат." << "\n"; cout << "Введите дробное число - "; cin >> n; cop = modf(n, &rub); cop = roadcent(cop); if (cop == 100) { cop = 0; ++rub; } cout << n << "руб. - это " << rub << " руб. " << cop << " коп." << "\n"; system("pause"); return 0; } 2nd file
double roadcent(double k) { k *= 100; int l = (int)(k * 10) % 10; if (l == 5) { return floor(k + 1); } else { return floor(k + 0.5); } } What is the result of the result? What are the options for correcting this error?