To avoid errors when comparing decimals it might be useful to use a function:
bool AreSame(double a, double b)
{
return fabs(a - b) < EPSILON;
}
where EPSILON could be represented by a small number such as .001
grabbed from this question.
EDIT: by including <limits>
one could use std::numeric_limits<double>::epsilon()