I keep getting the answer 48 instead of 233


#1


https://www.codecademy.com/en/courses/learn-java/projects/loan-payment-calculator?link_content_target=interstitial_project

I keep getting 48 as my answer instead of 233. I've tried to look closely at the code but I can't see what I'm doing wrong.

public class CarLoan {
	public static void main(String[] args) {
    int carLoan = 10000;
    int loanLength = 3;
    int interestRate = 5;
    int downPayment = 2000;
    if (loanLength <= 0 || interestRate <= 0) System.out.println ("Error! You must take out a valid car loan");
    else if (downPayment >= carLoan) System.out.println ("The car can be paid in full");
    else {
      int remainingBalance = (carLoan - downPayment);
      int months = (loanLength * 12);
      int monthlyBalance = (remainingBalance % months);
      int interest = (monthlyBalance * interestRate % 100);
      int monthlyPayment = (monthlyBalance + interest);
      System.out.println (monthlyPayment);
    }
	

	}
}


#2

Hi there.

int monthlyBalance = (remainingBalance % months);

The problem with this is that you're using the modulo operator. Modulo gets the remaining value from a division operation.

I believe you mean to use "/" (forward slash - divide)

This will divide the remaining balance by the number of months and show the correct result.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.