+ 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?
5 Réponses
+ 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.
+ 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
+ 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.
+ 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!
0
You're welcome...