Homework 3: Calculating Credit Card Interest

Assigned
  • February 7, 2024
Due
  • February 12, 2024 11:59pm
Collaboration
    Regular policies for collaboration apply to this homework assignment. Make sure you review and understand the policies on the syllabus before you discuss your work on this assignment with anyone else.
Submitting
    Upload your creditcard.c file to Gradescope when you are finished with the assignment. You can resubmit as many times as you like up until the deadline.

Overview

In this assignment, you will write a program to simulate calculating credit card interest whilst making only the minimum payment each month.

An individual’s credit card comes with an annual percentage rate (APR), which dictates how much interest you’d pay on a balance over a year. However, because users typically accrue charges over the course of a billing cycle, most credit card issuers calculate a so-called daily periodic rate (or DPR) and charge you interest based on the average daily balance during your billing cycle.

Details differ depending on your card issuer, but we will calculate the daily periodic rate as the annual percentage rate over 365.

The total interest charges accrued in your billing cycle is then your average daily balance multiplied by the DPR and the number of days in the billing cycle.

Example

Suppose your APR is 18%, then the DPR is calculated as

\[0.18 / 365 = 0.0004931506849\]

Now suppose you’re not adding any new charges and your forward balance is $42. If the month corresponding to your billing cycle has 31 days, the total interest you owe is

\[$42 * 0.004931 * 31 = $0.64\]

This is a pretty underwhelming amount, but as we’ll see, the compounding interest can be significant when you only pay the minimum amount each month.

Requirements

Please start the assignment by downloading creditcard.tar.gz and extracting it with the following terminal commands:

$ cd csc161/homework
$ tar xvzf ~/Downloads/creditcard.tar.gz
$ cd creditcard
$ code .

You can compile the program by running make, which uses the rules in the provided Makefile.

Write a program in creditcard.c that establishes an annual percentage rate and an initial balance as well as a monthly minimum payment. These three values should be assigned to variables that are easy to find and change in your code (see grading section below for more guidance). The program should then display the amount paid each month, along with the interest accrued and the remaining balance. Once the balance is paid off, it should report how many months it took to pay off the balance and the total amount paid.

For example, if we have a common APR of 18% and a monthly minimum of $35, we might see the following for a forward balance of $500.

Cycle  Month  Interest  Payment  Balance
    0      9  $   7.40  $ 35.00  $ 472.40
    1     10  $   7.22  $ 35.00  $ 444.62
    2     11  $   6.58  $ 35.00  $ 416.20
    3     12  $   6.36  $ 35.00  $ 387.56
    4      1  $   5.92  $ 35.00  $ 358.48
    5      2  $   4.95  $ 35.00  $ 328.43
    6      3  $   5.02  $ 35.00  $ 298.46
    7      4  $   4.42  $ 35.00  $ 267.87
    8      5  $   4.10  $ 35.00  $ 236.97
    9      6  $   3.51  $ 35.00  $ 205.47
   10      7  $   3.14  $ 35.00  $ 173.61
   11      8  $   2.65  $ 35.00  $ 141.27
   12      9  $   2.09  $ 35.00  $ 108.36
   13     10  $   1.66  $ 35.00  $  75.01
   14     11  $   1.11  $ 35.00  $  41.12
   15     12  $   0.63  $ 35.00  $   6.75
   16      1  $   0.10  $  6.86  $   0.00
After 17 months, you paid $566.86 on an initial balance of $500.00.

Your program should also follow these requirements:

  • Calculate the interest based on the number of days in the month. (Ignore leap years and pretend February is always 28 days).
  • You never pay more than the minimum or your current balance.
  • You never accrue new charges. Your goal is simply to pay off the card.
  • The printed table of information should include everything in the example above. It does not have to have the exact format, but it should be printed in a similarly clean format that is easy for humans to read.
  • In addition to your main function, which is of course required by C, you must write and use at least one other function (more than one is allowed). It is up to you to decide how best to break up the task, but your function should take in at least one parameter and return something other than void.
  • Your code should be well organized (as always), but in particular, it should be very easy for a grader to find and change values for the following variables: initial_balance, APR, monthly_minimum, and starting_month. (Hint: This should also give you a good idea about what sorts of tests you need to run!)

What to Submit

You will submit your work for this homework assignment on gradescope. Please upload your implementation in a file named creditcard.c, along with a testing transcript. You can create a testing transcript by running:

$ script tests.txt

The command above will record the commands you run and any outputs to a file named tests.txt. Run the program as many times as you need to thoroughly test your implementation, then run exit to end the transcript. Include tests.txt with your implementation when you submit your work to gradescope.

You should make sure your testing covers several combinations of initial_balance, APR, monthly_minimum, and starting_month.

It is in your interest to be thorough with your testing. Your tests must cover these cases to receive credit for the testing portion of your grade, but testing your code will help you find bugs that might otherwise have hurt your score in other parts of the assignment.

Grading

Your assignment will be graded on a scale of 0–100 points based on the following criteria:

  • Printed table includes all values requested and is neatly formatted (15 points)
  • Printed message to the user at the end (5 points)
  • Interest, payment, balance, and total amount paid are all calculated correctly (25 points)
  • A function (other than main) which takes in parameters and returns a non-void value is used in a way that aids in organization and understanding. (30 points)
  • Thorough testing demonstrated via a testing transcript (25 points)

There will be potential deductions for any code quality violations. For now, there are six requirements for quality code:

  1. Indent the body of all loops and conditionals one level deeper than the code just outside the loop. Be consistent with your indentation style.
  2. Use curly braces for every loop or conditional body, regardless of the number of lines.
  3. Include comments that explain what your code does. There should be at least one comment by the start of each loop and if–else block that explains what the purpose of that code is. The comment should not simply restate the code; it should add information for a human who reads the code and is confused.
  4. Give variables descriptive names that help a reader understand what they will be used for.
  5. Do not read from or display the value of any variable without first initializing it.
  6. Your code must compile with no errors and no warnings.