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.

Overview

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

Input

Your program should ask the user for:

  1. Initial amount in the savings account
  2. 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)
  3. 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)!!
  4. 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.
  5. 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.

Output

  1. 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.
  2. 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

  1. Present the user with a description of what the program will do.
  2. Request the specified input (initial amount, monthly deposit amount, and interest rate)
  3. Ask if the user wants a table of the balances for each month
  4. 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.
  5. The program should print a nicely formatted table, if requested (see the image for an example).
  6. 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.

Grading

This homework assignment is worth 25 points.