Sunday, July 12, 2009

How am i using this exp() math function wrong? C++ programming?

float newBalance = principal * ( 1 + interestRate )exp( years );





im trying to make it (1 + interestRate ) to the power of years.





Any insight would help.





Thanks

How am i using this exp() math function wrong? C++ programming?
There are a couple things wrong with your statement. First, you need to look up exp() and see what it does. It doesn't do what you think it does. Second, exp() is a function, not an operator, so you can't just stick it between two parenthesized expressions.





What you want is pow(). pow(1 + interestRate, years) will do what you want.
Reply:Syntax for exp() function is given below:





double exp ( double x );


float exp ( float x );


long double exp ( long double x );





I believe what you are trying to do is new balance = principal x (1 + interestRate) x exp(years)





for this use





float newBalance = principal * ( 1 + interestRate )*exp( years );





As (1 + interestRate)exp(years) is syntactically wrong... because its missing * operator between ( 1 + interestRate ) and exp() function which the compiler can't interpret... So leads to syntax error


No comments:

Post a Comment