I'm currently wondering why the following operation 20 / (10.0 / 6) results in 12 (double) when using C++. 10.0 is a double and 20 and 6 are integers. (10.0 / 6) results in 1.66 because 6 is first turned into a double. But why is 20 / 1.66 then 12 and not 12.05?
Sample program:
#include <iostream>
using namespace std;
int main()
{
cout << "20 / (10.0 / 6): " << (20 / (10.0 / 6)) << endl;
return 0;
}
Sample session (gcc, cygwin, Windows 10 - 64 bit):
$ echo -e '#include <iostream>
> using namespace std;
> int main()
> {
> cout << "20 / (10.0 / 6): " << (20 / (10.0 / 6)) << endl;
> return 0;
> }
> ' > test-div.cc
$ g++ -o test-div test-div.cc
$ ./test-div.exe
20 / (10.0 / 6): 12