-
Notifications
You must be signed in to change notification settings - Fork 0
/
10114-Loansome_Car_Buyer.c
45 lines (38 loc) · 1.17 KB
/
10114-Loansome_Car_Buyer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<stdio.h>
int main()
{
int number_of_months, depreciation_record;
double down_payment, amount_loan;
while(scanf("%d %lf %lf %d", &number_of_months, &down_payment, &amount_loan, &depreciation_record)==4)
{
double num_depreciation[1000]= {};
if(number_of_months<0)
break;
while(depreciation_record--)
{
int starting_month;
scanf("%d", &starting_month);
scanf("%lf", &num_depreciation[starting_month]);
}
double car_value = down_payment + amount_loan;
double owes=amount_loan;
double money_paid = amount_loan/number_of_months;
int i;
for (i = 0; i <= number_of_months; i++)
{
if (num_depreciation[i]==0)
num_depreciation[i] = num_depreciation[i - 1];
car_value = car_value * (1 - num_depreciation[i]);
if (owes<=car_value)
{
if(i==1)
printf("%d month\n", i);
else
printf("%d months\n", i);
break;
}
owes=owes-money_paid;
}
}
return 0;
}