MST
K.
Dzwonkiewicz
Program 19
Intro C++
As soon as you purchase an automobile the value of the car depreciates. Immediately on purchase, the car’s value drops by $1500 of its purchase price. For the next 3 years it drops 20% of the previous year’s price. For the next three years the value drops 15% of the previous year’s price. After that it will depreciate 12% each year. The value will never drop below $2000 (This is its salvage value).
YOU MUST USE FUNCTIONS!!!!!!!
*Your program will ask for… Enter new car price $
*It will print the value of the car each year, until it reaches salvage value.
*You will have three different functions called from within a while loop, the correct one is called only if the year value falls within the constraints given above. Call them twenty, fifteen, and twelve. Each one will return a value like this…
if (year > 0) and (year < 4) then price = twenty(price);
*Output like this…
*******************************
Enter new car price:
$22000
Value after purchase: $20500
Value after 1 year: $16400.00
Value after 2 years: $13120.00
Value after 3 years: $10496.00
Value after 4 years: $8921.60
Value after 5 years: $7583.36
Value after 6 years: $6445.86
Value after 7 years: $5672.35
Value after 8 years: $4991.67
Value after 9 years: $4392.67
Value after 10 years: $3865.55
Value after 11 years: $3401.68
Value after 12 years: $2993.48
Value after 13 years: $2634.26
Value after 14 years: $2318.15
Value after 15 years: $2039.97
Value after 16 years: $2000.00
*SALVAGE
**************************************
Another example:
**********************************
Enter new price:
$14000
Value after purchase: $12500.00
Value after 1 year:$10000.00
Value after 2 year:$ 8000.00
Value after 3 year:$ 6400.00
Value after 4 year:$ 5440.00
Value after 5 year:$ 4624.00
Value after 6 year:$ 3930.40
Value after 7 year:$ 3458.75
Value after 8 year:$ 3043.70
Value after 9 year:$ 2678.45
Value after 10 year:$ 2357.04
Value after 11 year:$ 2074.20
Value after 12 year:$ 20000.00 *SALVAGE
*********************************************
Program stub
Ask new car price
Deduct 1500, print out new amount
Initialize year to 0
Start while……loop while(price > 2000) {
Year+1
If year 1-3 then price =
twenty(price) calls
function twenty
If year 4-6 then price = fifteen(price) taking
in price, returning
If 7-? Then price =
twelve(price) lowered
price
print out chart value
end while loop
print salvage value of $2000
three functions calculate price as
depreciation of 20%, 15%, or 12%
for example
if (year > 0
&& year <= 3) price = twenty(price);
if (year > 3
&& year <= 6) price = fifteen(price);
. .
. .
. .