CMSC104, Spring 2002

Programming Project 4

Monthly Car Payment Calculator

Out: Tuesday, March 19, 2002
Due: Thursday, April 4, 2002 before midnight


The Objective

This project is designed to give you practice writing a C program on your own. It will give you practice with while loops, as well as experience working with functions from the math library.

The Background

It is time for me to purchase a new car and I need your help. I have finally decided on the car, the Lexus SC430, but I am not sure exactly how much the monthly payments will be. Before I can purchase the car, I need to know if I can afford the monthly payments on the car.

The Task

Your job is to write a program that will calculate a monthly car payment, given the necessary input. See below for an explanation of input. Here is the formula used to calculate the monthly payment: monthly payment = P ( r / 12 ) ------------------------- -m (1 - ( 1 + r / 12 ) ) where P = the principal amount, r = the interest rate (in decimal form) and m = the number of months Your program should accept the following input from the user: Based on the user input, you are to calculate the amount of principal. The principal is considered to be the original amount of debt on which interest is calculated. Therefore, you must adjust the price of the car to reflect any additions (such as sales tax) or deductions (such as down payment). You should then calculate the monthly payment, using the above formula. Note that in the formula, the interest rate is in decimal format. The interest (as well as sales tax) should be read in from the user in percent format. For example: 7.5% would be 7.5 in percent format and .075 in decimal format.

Your program should allow the user to keep calculating monthly payments until he or she wishes to quit. The user should select a 1 to calculate another payment or a 0 to quit.

Assumptions

Sample Output

linux2[47]% a.out $$$$$$ Monthly Car Payment Calculator $$$$$$ Enter the price of the car: 15000 Enter the sales tax (%): 5.0 Enter the number of months: 48 Enter the interest rate (%): 7.5 Enter the amount of the down payment: 5000 Enter the value of trade-in: 1200 Enter rebate amount: 1000 The monthly payment is: $206.73 Would you like to calculate another payment? Please enter 1 for yes or 0 to quit: 1 Enter the price of the car: 15000 Enter the sales tax (%): 5.0 Enter the number of months: 36 Enter the interest rate (%): 6.0 Enter the amount of the down payment: 0 Enter the value of trade-in: 0 Enter rebate amount: 0 The monthly payment is: $479.15 Would you like to calculate another payment? Please enter 1 for yes or 0 to quit: 1 Enter the price of the car: 15000 Enter the sales tax (%): 5.0 Enter the number of months: 48 Enter the interest rate (%): 0 Enter the amount of the down payment: 5000 Enter the value of trade-in: 0 Enter rebate amount: 0 The monthly payment is: $223.96 Would you like to calculate another payment? Please enter 1 for yes or 0 to quit: 0 Thank you for using the monthly car payment calculator! linux2[48]%


Important Note : You must tell the compiler where to find the math library, or else your program will not work. This is accomplished by using the -lm (the lowercase letter 'l' not the number one) option when compiling. So in order to compile a program that calls a function in the math library, not only do you have to #include the math.h header file, but also must compile with the -lm option. For a source file called proj4.c, that command would be :

linux2[269]% gcc -ansi -Wall proj4.c -lm

Submitting the Program

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104_0101 Proj4 proj4.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.

submitls cs104_0101 Proj4