0

Facing logical error. Need help to sort things up.

There is a code I made to calculate Simple and Compound interest. But whatever parameters I set for calculating compound interest, it always comes out to be zero. I went by the following approach: Amount = Principal + Interest Interest = Amount - Principal -------(1) Amount = Principal( 1+ Rate of interest/100)^(No.of years) ----------(2) { as the interest has to be compounded annually } So, interest comes out to be: C.I= P(1 + r/100)^(t) - P =>C.I= P[(1+ r/100)^(t) -1] Where did I go wrong? https://code.sololearn.com/cemoFnS5DV8i/?ref=app

18th Sep 2018, 12:13 PM
Ayushmaan Dash
Ayushmaan Dash - avatar
4 ответов
+ 5
Try using float instead of int
18th Sep 2018, 1:12 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 3
You probably entered to low values, I tried 10>>500>>2 and it worked. If values are too low it won't work, beacuse you divide it by 100.
18th Sep 2018, 12:46 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
0
Olek Szczepura It's not about big or small values. For example, if the principal amount is 100, the rate of interest is 10 and the time period is 2 years then the interest should be 21 but it's giving 30 as output
18th Sep 2018, 12:59 PM
Ayushmaan Dash
Ayushmaan Dash - avatar
0
Olek Szczepura Thanks for the tip. Using float solved my problem 😃
18th Sep 2018, 4:13 PM
Ayushmaan Dash
Ayushmaan Dash - avatar