2
06 Copyright © 2002, Department of Systems and Computer Engineering, Carleton University 1 Exercise 3 Imagine that you’re buying a car. You don’t have to put any money down, but do have to make regular monthly payments. The process works as described below. The description assumes that the car costs $10,000, that you’ll be paying $500 a month, and that interest is charged at 5%. The basic idea applies, however, whatever the actual numbers are. As you drive away, you owe $10,000. A month later, this is increased by the interest for the month. This is equal to the amount owing times the monthly interest rate (the annual rate divided by 12) divided by 100, which works out to.41.67. You now owe $10,041.67. Your first monthly payment is now taken into account. This reduces your amount owing to $9,541.67. Another month later, your debt is increased by the interest for this month. This time the interest works out to $39.76, and you now owe $9581.43. Your second monthly payment is now considered, reducing your amount owing to $9081.43. And so on, and so on, until your debt is wiped out. When the time comes for your last payment, you pay only whatever you owe at this point. In this particular case, your last payment would be $463.07. Write a program that produces a table showing 1/. how many months it takes to pay off a car, 2/. what the last payment will be, and 3/. the total interest charges. The cost of the car and the monthly payment are to be read in, and the table is to cover interest rates from 0 to 10% (in steps of 1%). Running the

Exercise 3

  • Upload
    jania

  • View
    24

  • Download
    0

Embed Size (px)

DESCRIPTION

Exercise 3. - PowerPoint PPT Presentation

Citation preview

Page 1: Exercise 3

ECOR 1606 Copyright © 2002, Department of Systems and Computer Engineering, Carleton University 1

Exercise 3

Imagine that you’re buying a car. You don’t have to put any money down, but do have to make regular monthly payments. The process works as described below. The description assumes that the car costs $10,000, that you’ll be paying $500 a month, and that interest is charged at 5%. The basic idea applies, however, whatever the actual numbers are.

As you drive away, you owe $10,000.

A month later, this is increased by the interest for the month. This is equal to the amount owing times the monthly interest rate (the annual rate divided by 12) divided by 100, which works out to.41.67. You now owe $10,041.67.

Your first monthly payment is now taken into account. This reduces your amount owing to $9,541.67.

Another month later, your debt is increased by the interest for this month. This time the interest works out to $39.76, and you now owe $9581.43.

Your second monthly payment is now considered, reducing your amount owing to $9081.43.

And so on, and so on, until your debt is wiped out. When the time comes for your last payment, you pay only whatever you owe at this point. In this particular case, your last payment would be $463.07.

Write a program that produces a table showing 1/. how many months it takes to pay off a car, 2/. what the last payment will be, and 3/. the total interest charges. The cost of the car and the monthly payment are to be read in, and the table is to cover interest rates from 0 to 10% (in steps of 1%). Running the sample executable supplied should make it clear exactly what is required.

Page 2: Exercise 3

ECOR 1606 Copyright © 2002, Department of Systems and Computer Engineering, Carleton University 2

The cost of the car must be at least $1000, and the payment must be more than 1% of the price of the car. If the values entered do not meet these criteria, your program should output an error message and have the user-re-enter both values. And so on, and so on, until valid values are entered.

Each time that interest is calculated, the amount should be rounded to the nearest cent. This can be achieved by using the following assignment statement:

rounded_interest = int((unrounded_interest * 100) + 0.5) / 100.0;

To see how this works, try hand evaluating the expression with “unrounded_interest” equal to 11.333, 12.005, and 9.452.

Properly formatting the table requires features that, as this exercise is posted, have yet to be covered. They will be covered, however, before the assignment is due. In the time being, don’t worry about the formatting (just get the right values and output them on the right lines). Once you’ve got everything else working, dealing with the formatting should only take a few minutes.