d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Why Am I Getting An Error On This In Java?
12Next
Add Reply New Topic New Poll
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 10:00am
double M = P *([I(1+I)^N])/[((1+I)^N)-1]);

says there is an error on the outside parenthesis and the division sign.
Member
Posts: 6,481
Joined: Jul 5 2009
Gold: 0.70
Oct 13 2013 10:25am
double M = P * ( [ I ( 1 + I ) ^ N ] ) / [ ( ( 1 + I ) ^ N ) - 1 ] );

The one at the very end before the semicolon doesn't have a matching parenthesis. Add another one at the beginning of the expression to encapsulate the whole thing. P * ( ( [ instead of P * ( [
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 11:17am
Quote (mebeatyou @ Oct 13 2013 11:25am)
double M = P * ( [ I ( 1 + I ) ^ N ] ) / [ ( ( 1 + I ) ^ N ) - 1 ] );

The one at the very end before the semicolon doesn't have a matching parenthesis. Add another one at the beginning of the expression to encapsulate the whole thing. P * ( ( [ instead of P * ( [


double M = P*(([I(1+I)^N])/[((1+I)^N)-1]);

I have that and am still getting an error under these:

double M = P*(([I(1+I)^N])/[((1+I)^N)-1]);
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 11:21am
Then I changed it to this

double M = P*(([I(1+I)^N])/((((1+I)^N)-1)));

and get an error only under:

double M = P*(([I(1+I)^N])/((((1+I)^N)-1)));
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 11:22am
It says syntax error expression expected after this token

talking about that red parenthesis
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 11:52am
Quote (sarge799 @ Oct 13 2013 12:45pm)
Again, always use * to multiply.
Also you have several unneeded parenthesis.


Code
public static double calcMonthlyPayment( ) { // start calcMonthlyPayment

double P = getLoanAmount();
int N = getLoanLength();
double I = getInterestRate();
double M = P*((I*(1+I)^N)/(((1+I)^N-1)));

return M;
} // end calcMonthlyPayment


so now I have that, and now it says:

The operator ^ is undefined for the argument type(s) double, int
Member
Posts: 40,900
Joined: Jul 12 2004
Gold: 1,524.85
Oct 13 2013 12:00pm
Quote (GetSpanked @ Oct 13 2013 12:52pm)
Code
public static double calcMonthlyPayment( ) { // start calcMonthlyPayment

double P = getLoanAmount();
int N = getLoanLength();
double I = getInterestRate();
double M = P*((I*(1+I)^N)/(((1+I)^N-1)));

    return M;
} // end calcMonthlyPayment


so now I have that, and now it says:

The operator ^ is undefined for the argument type(s) double, int


Exponents need to use the Math.pow function.
For example, (1+I)^N should be replaced by pow((1+I),N)
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 12:21pm
Quote (sarge799 @ Oct 13 2013 01:00pm)
Exponents need to use the Math.pow function.
For example, (1+I)^N should be replaced by pow((1+I),N)


Code
public static double calcMonthlyPayment( ) { // start calcMonthlyPayment

double P = getLoanAmount();
int N = getLoanLength();
double I = getInterestRate();
double top1 = I*(1+I);
double top = Math.pow(top1,N);
double bottom1 = (1+I);
double bottom2 = Math.pow(bottom1,N);
double bottom = bottom2 - 1;
double M = P*(top/bottom);

return M;
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Oct 13 2013 12:23pm
did that wrong

fixed

Code
public static double calcMonthlyPayment() { // start calcMonthlyPayment

double P = getLoanAmount();
int N = getLoanLength();
double I = getInterestRate();
double top1 = (1+I);
double top2 = Math.pow(top1,N);
double top = I*top2;
double bottom1 = (1+I);
double bottom2 = Math.pow(bottom1,N);
double bottom = bottom2 - 1;
double M = P*(top/bottom);

return M;
} // end calcMonthlyPayment
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Oct 13 2013 02:09pm
Goddamn give your variables meaningful names that aren't single capital letters.
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll