Amateur question.

This is a discussion on Amateur question. within the C++ Programming forums, part of the General Programming Boards category; This program is supposed to take the four inputs and use them to calculate the balance for each year of ...

I think your formula for calculate the balance is getting to pretty big numbers (that get beyond the range for floating numbers in C). Declare double getBalance(float p, float i, float q, int n); and see what happens.
Here is the result of your program on my compiler:

Code:

//my output
This program will request that you enter
values for:
a principal amount (P)
an annual interest rate (I)
times compounded per year (Q)
years in account (N)
The program will then calculate and print
the balance for each year up through year N.
--------------------------------------------
Please enter your principal amount:
Please enter the annual interest rate:
Please enter the times compounded per year:
Please enter the number of years in the account:
--------------------------------------------
Principal amount======================> 5
Annual interest rate==================> 6
Times compounded per year=============> 7
Years to keep in account==============> 8
--------------------------------------------
Balance after 1 years: 5.95261e+006
--------------------------------------------
Balance after 2 years: 3.54335e+013
--------------------------------------------
Balance after 3 years: 2.10922e+020
--------------------------------------------
Balance after 4 years: 1.25553e+027
--------------------------------------------
Balance after 5 years: 7.4737e+033
--------------------------------------------
Balance after 6 years: 1.#INF
--------------------------------------------
Balance after 7 years: 1.#INF
--------------------------------------------
Balance after 8 years: 1.#INF
--------------------------------------------
--------------------------------------------
Would you like to do another calculation? Enter Y or N:

Thanks, I tried that and this is my output using doubles instead of floats for getBalance. Seems like the same thing basically. Just not sure, what the issue is. It seems correct to me, but I don't know.

Code:

Program SAVE
--------------------------------------------
This program will request that you enter
values for:
a principal amount (P)
an annual interest rate (I)
times compounded per year (Q)
years in account (N)
The program will then calculate and print
the balance for each year up through year N.
--------------------------------------------
Please enter your principal amount:
1000
Please enter the annual interest rate:
4.0
Please enter the times compounded per year:
2
Please enter the number of years in the account:
5
--------------------------------------------
Principal amount======================> 1000
Annual interest rate==================> 4
Times compounded per year=============> 2
Years to keep in account==============> 5
--------------------------------------------
Balance after 1 years: 9e+06
--------------------------------------------
Balance after 2 years: 8.1e+13
--------------------------------------------
Balance after 3 years: 7.29e+20
--------------------------------------------
Balance after 4 years: 6.561e+27
--------------------------------------------
Balance after 5 years: 5.9049e+34
--------------------------------------------
--------------------------------------------
Would you like to do another calculation? Enter Y or N:

Yeah you're right. However the same problems remain when I use what four percent actually would be.

Code:

Program SAVE
--------------------------------------------
This program will request that you enter
values for:
a principal amount (P)
an annual interest rate (I)
times compounded per year (Q)
years in account (N)
The program will then calculate and print
the balance for each year up through year N.
--------------------------------------------
Please enter your principal amount:
1000
Please enter the annual interest rate:
0.04
Please enter the times compounded per year:
2
Please enter the number of years in the account:
5
--------------------------------------------
Principal amount======================> 1000
Annual interest rate==================> 0.04
Times compounded per year=============> 2
Years to keep in account==============> 5
--------------------------------------------
Balance after 1 years: 1.0404e+06
--------------------------------------------
Balance after 2 years: 1.08243e+12
--------------------------------------------
Balance after 3 years: 1.12616e+18
--------------------------------------------
Balance after 4 years: 1.17166e+24
--------------------------------------------
Balance after 5 years: 1.21899e+30
--------------------------------------------
--------------------------------------------
Would you like to do another calculation? Enter Y or N: