+ 2

Loan Calculator Help

Hello, I was attempting the code project and this is my code for it: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for (int i = 0; i > 3; i++){ int payment = amount * (10/100); int remaining = amount - payment; amount = remaining; } System.out.println(remaining); } } Can someone help me with what I did wrong here?

5th Sep 2022, 6:37 PM
Shahriar Ahmed Ratul
Shahriar Ahmed Ratul - avatar
5 Answers
+ 1
i > 3 makes it infinite loop. Use i<3 don't use braces around (10/100), just use 10/100. Else use 10.0 or 100.0 a double type value instead 10 or 100 . result need type cast back. print amount, not remaining.
5th Sep 2022, 6:43 PM
Jayakrishna🇮🇳
Jayakrishna🇮🇳 - avatar
+ 1
Thank you so much, really silly mistake on my part. Did not see that I put the > symbol instead of <. Whoops. Really appreciate the prompt response. I am getting this error now, I thought I defined remaining already but the error indicates something is wrong here. /usercode/Program.java:14: error: cannot find symbol System.out.println(remaining); ^ symbol: variable remaining location: class Program
5th Sep 2022, 6:48 PM
Shahriar Ahmed Ratul
Shahriar Ahmed Ratul - avatar
+ 1
'remaining' you declared in loop. So it only exist in loop. After loop, it don't exist. It's scope is local to loop. Print amount.
5th Sep 2022, 6:54 PM
Jayakrishna🇮🇳
Jayakrishna🇮🇳 - avatar
+ 1
Ah ok, thanks again will try to amend it, and hopefully it works. Edit: Yep that fixed it. Thanks a lot for your help!
5th Sep 2022, 6:57 PM
Shahriar Ahmed Ratul
Shahriar Ahmed Ratul - avatar
0
You're welcome...
5th Sep 2022, 7:08 PM
Jayakrishna🇮🇳
Jayakrishna🇮🇳 - avatar