-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTste.cpp
More file actions
39 lines (33 loc) · 679 Bytes
/
Tste.cpp
File metadata and controls
39 lines (33 loc) · 679 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
int main() {
int loanDur, nRec;
double downPayment, loan, decP[101];
while (true) {
cin >> loanDur >> downPayment >> loan >> nRec;
if (loanDur < 0)
break;
int m;
double p;
while (nRec--) {
cin >> m >> p;
for (int i = m; i < 101; i++)
decP[i] = p;
}
int now = 0;
double monthlyPayment = loan / loanDur;
double curVal = (loan + downPayment) * (1 - decP[0]);
double curLoan = loan;
while (curVal < curLoan) {
now++;
curLoan -= monthlyPayment;
curVal = curVal * (1-decP[now]);
}
cout << now << " month";
if (now != 1)
cout << "s";
cout << endl;
}
return 0;
}