This is a great example of the pitfalls of trying to write code on the fly.
OP, when you don't fully understand the subject for which you are programming, in this case finance, then first write pseudocode to organize your thoughts about the problem.
I KNOW that if you had pseudocoded your problem you would not have tried to compute the future value before the user inputted the needed parameters, as Darkmaster pointed out.
I also believe that if you had also created test data by hand and tested your program with it, you would have discovered your misplaced parenthesis error right away.
If you are still having difficulty after the posts to help you, then go back to square one and pseudocode your problem. Then you can get your program correct.
I am teaching myself C++ and am far from an expert. My very first intro to computer science course was as a freshman in 1980 and we used BASIC. The professor taught us pseudocode. As I try to write programs for more complex problems, I really see how ESSENTIAL pseudocoding is. I am surprised it is not emphasized more.
I decided to give an example.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Problem: compute the future value of an ordinary annuity.
The user inputs the needed parameters.
The needed parameters are:
1) the number of compounding periods
2) the length of the compounding period
3) the interest rate per compounding period
4) the annuity amount
The future value is computed using the formula
Future value = annuity amount times [(the interest rate + 1)^number of
periods - 1] divided by the interest rate.
Display the future value.
The user indicates if another computation is to be made.
|
If you want bonus points, add filters to make sure the interest rate is not negative, the compounding period is at least daily, the number of periods is not negative, the annuity amount is not negative.
N.B. There is a difference between an ordinary annuity, (payment made at end of the period like a salary), and an annuity due, (payment made end beginning of the period like rent).