Homework 2: Double Your Savings
This homework is to be done individually. You may ask your instructor for help, but do not ask other students, tutors, or mentors for assistance.
This program gives you more practice with reading input from the user, conditionals and loops. You will also need to format output so that it makes a neat-looking table of numbers in a specific format. See King 8.1 for some hints.
See the "Grading" section below for specific criteria for this assignment. As with all projects and homework, the style guidelines apply to this assignment, and points may be deducted for poor style, readability, and testing. Feedback will be given using a version of this checklist.
This program will calculate how long it takes to double an amount of money in a savings account, given a specific amount that is saved each month and an interest rate, which will be compounded monthly.
The program will give the user the option to print out a table that shows the balance of the savings account each month. If the user does not want to see the table, they should just be informed of how many months it will take to save enough to have doubled the initial amount.
Note: the final balance will almost certainly be MORE than twice the intial amount, and this is fine. Your program should terminate when the total balance is greater than or equal t twice the intial amount of money.
Input and Output Format
Your program should ask the user for:
- Initial amount in the savings account
- The amount that will be deposited by the user each month (this will remain consistent while running the program, like an automatic deduction from a paycheck)
- The interest rate that will be paid on the account. Your prompt to the user needs to specify if they should enter it as a whole number (i.e. 6 for an interest rate of 6%) or as a percentage (i.e. 0.06)!!
- You need to ask the user if they want a table printout of the monthly balances or not. You can accept a 'y' or 'n' OR a "yes" or "no". But you need to be able to accept a character or a string as input to get full points.
Important Note: Since you are using scanf() to read a character right after a line in which you read a number, you will need to handle the invisible newline character. Read this page on using scanf with mixed input lines to understand what is happening and how to fix it. Ask your instructor if questions remain.
- Your program should be able to print a table of the monthly balances until twice the initial balance is reached. The first column in the table should indicate the month. The second column should include the current balance for that month. The dollar amounts must be formatted so that there are only two decimal places.
- At the end of the program's run, you should print out the number of months required to double the initial deposit plus the current balance in the account.
An example should look like:
What Your Program Must Do
- Present the user with a description of what the program will do.
- Request the specified input (initial amount, monthly deposit amount, and interest rate)
- Ask if the user wants a table of the balances for each month
- Calculate monthly interest rate. Be careful, since this is often entered as a whole number (i.e. 6%), but it will need to be converted to a percentage (divided by 100). Interest rates are also usually quoted as annual rates, but you will be calculating the interest monthly; so the rate futher needs to be divided by 12. See King 8.1 for help with these calculations, if necessary.
- The program should print a nicely formatted table, if requested (see the image for an example).
- The program must print the number of months required to double the initial deposit plus the final balance. Money values are usually printed with two decimal places.
This homework assignment is worth 25 points.
- [2 points] Introductory message explaining what the program does
- [3 points] Request inputs from user (with reminders of acceptable format)
- [2 points] Ask if the user wants the balance table printed
- [3 points] Calculate monthly interest rate from the entered annual percentage rate (APR)
- [5 points] Print a table formatted in two columns with balance printed to two decimal places, when requested
- [5 points] Final print out of number of months required and ending balance
- [2 points] Test plan lists possible user errors (such as entering 0.00 for any numeric value)
- [3 points] Test script shows testing of at least 3 different scenarios and tests possible errors, showing how the program recovers from them.