int main() {
double number1;
double number2;
double difference;
const double close = 0.01;
cout << "enter two numbers" << endl;
while (cin >> number1 >> number2) {
if (number1 > number2) {
cout << "the smaller value is: " << number2 << endl;
cout << "the larger value is: " << number1 << endl;
} else if(number1 < number2) {
cout << "the smaller value is: " << number1 << endl;
cout << "the larger value is: " << number2 << endl;
} else {
cout << "the numbers are equal" << endl;
}
difference = abs(number1 - number2);
cout << "the difference is: " << difference << endl << endl;
if (difference == close) {
cout << "since the difference is: " << difference << " it is almost the same number" << endl;
}
cout << "Enter two numbers: " << endl;
}
keep_window_open();
return 0;
}
Why does it detect that the number is "almost the same" when I use inputs 0
and 0.01
, but it does not write out the same message when the input is anything else like 5.59
and 5.6
?