I started learning c++, but I have an issue.
I’m trying to do a rule of three in c++ but I get a wrong result. Should give me 55.549,38775510204, and I get -41842.000000000000
What I’m doing wrong??
In C# I do this and works fine:
decimal ruleOfThree = decimal.Divide(decimal.Multiply(32000, 76554), 44100);
In C++ I’m doing this:
long double ruleOfThree = ((32000 * 76554) / 44100);
>Solution :
I haven’t tested this on a C++ compiler, but something like:
long double ruleOfThree = ((32000.0 * 76554.0) / 44100.0);
I.e. make sure the 3 multipliers are doubles, not integers.