expected "(" error,

Can not understand why the error, after trying to solve it 100 ways

Page 1 of 1

3 Replies - 391 Views - Last Post: 13 April 2010 - 05:13 AM Rate Topic: -----

#1 HDRStudent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-April 10

expected "(" error,

Posted 12 April 2010 - 05:37 PM

My program is getting a error I can not figure out:

public class mortCalcSR1
{
	public static void main (String[] args)throws InterruptedException
	{

	double loanAmount = 200000;//The principal amount of the loan//
	int term = 30;//The terms of the loan in years//
	double interest =.0575;//The interest rate on the loan//
	double monthlyPayment; //The monthly payment of the loan//
	double currentPrincBalance=0;//This is the current balance of the principal only //

		monthlyPayment=(loanAmount*(interest/12))/(1-(Math.pow(1/(1+interest/12),(term*12))));//Calculates the interest rate.//

			System.out.println("Monthly Payment is $"+ monthlyPayment);//Prints the monthy payment//
	//Change request #1//
	double loanBalance=0;//variable holding the loan balance//
	double InterestPaid=0;//variable holding the interest paid on the loan//
	int lineCount=0;//variable holding the counting of the lines//

	while loanBalance=(loanAmount-monthlyPayment);//takes the laon amount and subtracts the monthly payment//
		interestPaid=(monthlyPayment*interest);//this calculates the monthly interest//
		{
		if (loanBalance <=0){ //if the laons balance is less than zero the following will print//
			System.out.println("Congratulations, you now own your home!");//prints the the loan has been apis off//
}
		if (loanBalance>0){//if the laons balance is more than zero, the following will print//
			System.out.println("Loan balance is $"+loanBalance);//displays the loan balance//
			System.out.println("Your accumulated interest paid is"+interestPaid);//displays the interest that has been paid on the loan//
}
		if(lineCount=30){//counts the lines up to 30 each interval//
			Thread.sleep(5000);//takes a 5 second pause//
			throw InterrupedException;//allows for interruption//
}

											}
							}
						}



I am getting the following error:
C:\Users\Public\Documents\AXIA\Java\mortCalcSR1.java:21: '(' expected
while loanBalance=(loanAmount-monthlyPayment);//takes the laon amount and subtracts the monthly payment//
^
C:\Users\Public\Documents\AXIA\Java\mortCalcSR1.java:21: ')' expected
while loanBalance=(loanAmount-monthlyPayment);//takes the laon amount and subtracts the monthly payment//
^
2 errors

Tool completed with exit code 1

Can you help me understand why? I have been trying to fix this for three days and am at a loss. I have tried every form of using the ")" and nothing seems to work. I need advice from a programmer. Thank you kindly for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: expected "(" error,

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: expected "(" error,

Posted 12 April 2010 - 05:38 PM

You need to have parentheses around the conditional in your while loop. also, get rid of the semicolon after it, the structure looks like this:

while(condition){
//do this
}




You want to use '==' for equality comparison rather then '=' which is the assignment operator.
Was This Post Helpful? 0
  • +
  • -

#3 HDRStudent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-April 10

Re: expected "(" error,

Posted 12 April 2010 - 11:35 PM

I'll try that, thank you so much for the reply. I really appreciate you taking the time to help me.
Heather
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: expected "(" error,

Posted 13 April 2010 - 05:13 AM

In addition to what KYA said, the way you write your while statement, you should not have semicolons after the while loop as you have here, so you should remove them:
while (loanBalance == (loanAmount-monthlyPayment);//<<these semicolon

also, the curly braces should be right after the condition, not as you have here to enclose all the code you want to execute in the while loop, so:
while (loanBalance=(loanAmount-monthlyPayment){//<<<curly braces should start here 
                interestPaid=(monthlyPayment*interest);
                {///<<these should be moved

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1