Add Epsilon Before Casting Double to Integer!

Problem: Given a real number in exactly two digits after the decimal point, and another integer. Print their product, rounded down to the nearest integer.

You may start to code this way:

double a;
int b;
cin >> a >> b;
int c = a * b;
cout << c << endl;

Do you think this is correct? Well, almost. Now, try this input:

0.94 8700

What will the output be? [Read more…]