Problems multiplying | Sololearn: Learn to code for FREE!

+5

Problems multiplying

A while ago I saw a SL challenge to make a program which multiplies as we do with pen & paper. So I made mlTpliKshn.cpp -- but on my Android in cppDroid app. It worked fine for integers, so I thought I'd include real #s. Errors resulted such as 1.25*20=24.8. With "cout" debugging, I realised fp#s must be rounded up when converting to integer, which must be done to display intermediate prod. of mult. After repairs, prog works fine in cppDroid, but I still get errors​ for same code in SL. Thanx 2 any helperz

2/2/2018 11:53:47 PM

Eric Zatarack

4 Answers

New Answer

+8

thanks again, John. I temp forgot that pow() is a real # function. I inserted "round" in front of it, tested the prog, and it works correctly for the #s that gave errors b4. I'm going to try to reduce the duplicate functions to trim down the code & save memory, etc, as you mentioned. thank you very much!

+7

thank you John Wells, I didn't know how to include the program, but I'm glad you did it for me. (I tried + insert, but it didn't work.)

+6

You should include your code to make it easier for people to help you. https://code.sololearn.com/cDJ1fT2EdNkM

+6

Your error comes on line 83. static_cast<int>(power(10,2)) returns 99 not 100. Use round instead to fix it. On a side note, coding duplicate methods is a waste of time, memory, and most importantly is a possibility to introduce bugs into your program. Take for instance, you decide to add an improvement to one of those methods. It becomes likely that you test the improvement for only one before touching the other. Now, you attempt to update the second and forget a change or forget to rename to use the correct properties so the second isn't doing exactly the same as the first.