+ 1

[SOLVED] Only get correct on the two first cases of loan calculator

I tried these two solutions for the loan calculator test and got correct on the two first that I could see, but not the three next that is locked, and I really wonder why this does not work? First try: int fP = (amount / 100) * 90; int sP = (fP / 100) * 90; int tP = (sP / 100) * 90; if(amount > 0){ System.out.println(tP); } Second try: int payments = 1; do { amount = (amount / 100) * 90; payments++; } while (payments <= 3); System.out.println(amount);

11th Jan 2022, 5:54 PM
Martin Valdés Mallaug
3 Answers
+ 2
That makes sense! Thank you very much! (-:
11th Jan 2022, 6:34 PM
Martin Valdés Mallaug
+ 3
It's because integer calculation. This line makes the difference : amount = amount / 100 * 90; or amount = amount * 90 / 100; For small amount less 100 for example, the result of amount / 100 becomes 0. And 0 * 90 is also 0 That's not good. Change this formular to amount = amount * 90 / 100; So it works also for smaller amounts.
11th Jan 2022, 6:21 PM
Coding Cat
Coding Cat - avatar
+ 1
Sorry, start of code is this: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt();
11th Jan 2022, 5:55 PM
Martin Valdés Mallaug