Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue with a math rule of three in c++

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading