ECE 231 – Fall 2009
Programming Assignment 2
Due: Tuesday, September 8, 2009 at 11:59 PM
Write a C++ program that based on a menu choice either calculates an amount you have gained in an account using the compound interest formula given a principle, interest rate, the number of compounds per year and the number of years or the continuous compounding formula that requires the principal, interest rate and number of years or exits.
The formulas you will use are described as follows:
where A is amount, P is principle, r is interest rate (in
decimal form,) n is the number of compounds per year (annually would be 1,
monthly would be 12, etc,) and t is time in years (one and a half years would
be 1.5.) For this calculation, you will
need to ask the user to enter the principle, the interest rate, the time and
the number of compounds per year.
where A is amount, P is principle, r is interest rate (in
decimal form,) and t is time in years.
For this calculation, you will need to ask for the principle, the
interest and the time.
NOTE: In both cases, the interest rate should be entered as follows: 12 for 12 percent, 14.5 for 14.5% (i.e. your program will need to convert the number to decimal.)
Your program should give the user a menu choice: (1) to use the compound interest formula, (2) to use the continuous compounding formula or (3) to exit. Any other number will result in giving the user an error, but asking them to enter 1, 2, or 3 again.
The calculations of the interest must be done using functions. You will need to use a loop to continuously give the user the menu and a switch() statement or if() statements to determine what the user entered.
HINT: You can use the pow() function to calculate a power (exponent.) For example, to calculate
, you would use x = 7 *
pow( 3, (4 * 2) ); To use the
exponential function, use exp(). To calculate
, use z = 4 * exp( (6 *
y) ); These functions are located in
the <math.h> header file.
An example output would be as follows:
Enter a 1 to calculate a compounded amount
Enter a 2 to calculate an amount compounded
continuously
Enter a 3 to exit the program
1
Please enter the Principle: 1000
Enter the interest rate: 10
Enter the number of compounds per year: 4
Enter the number of years in the account: 1
The amount compounded 4 times a year at an interest
rate of 10% for 1 year is $1103.81
Enter a 1 to calculate a compounded amount
Enter a 2 to calculate an amount compounded continuously
Enter a 3 to exit the program
2
Please enter the Principle: 1000
Enter the interest rate: 10
Enter the number of years in the account: 1
The amount compounded continuously at an interest
rate of 10% for 1 year is $1105.17
Enter a 1 to calculate a compounded amount
Enter a 2 to calculate an amount compounded
continuously
Enter a 3 to exit the program
4
Invalid Entry!
Enter a 1 to calculate a compounded amount
Enter a 2 to calculate an amount compounded
continuously
Enter a 3 to exit the program
3
Thank you for using the program!