4
I’m solving the 1021 issue of the Judge URI, but I have a problem with the accuracy of my input value. Follow the base code:
#include <iostream.h>
int main(){
double a;
cin >> a;
}
The problem is that, if I insert for example 0.35 in the input, for some reason the variable a receives 0.349999, but I need this lost 0.001 to resolve the issue, what I can do to fix this?
If you need precision then do not use float or double variables because these data types are inherently inaccurate. If you effectively need to work with these types of data then considering an error will solve the problem, e.g. + or an error of 1E-5 (or 0.00001). For this particular problem you can use an integer data type and multiply the values by 100 to determine the amounts of banknotes and coins.
– anonimo