Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cmath>
- using namespace std;
- int indexOfAccountNumber = 0;
- int indexOfAmountLoaned = 1;
- int indexOfTermInYears = 2;
- int indexOfAnnualInterestRate = 3;
- int indexOfMonthlyPayment = 4;
- int getInput(double account[4][5]) {
- account[0][indexOfAccountNumber] = 101;
- account[1][indexOfAccountNumber] = 102;
- account[2][indexOfAccountNumber] = 103;
- account[3][indexOfAccountNumber] = 104;
- account[0][indexOfAmountLoaned] = 95000.00;
- account[1][indexOfAmountLoaned] = 100000.00;
- account[2][indexOfAmountLoaned] = 125000.00;
- account[3][indexOfAmountLoaned] = 150000.00;
- account[0][indexOfTermInYears] = 15;
- account[1][indexOfTermInYears] = 30;
- account[2][indexOfTermInYears] = 30;
- account[3][indexOfTermInYears] = 30;
- account[0][indexOfAnnualInterestRate] = 0.06875;
- account[1][indexOfAnnualInterestRate] = 0.055;
- account[2][indexOfAnnualInterestRate] = 0.045;
- account[3][indexOfAnnualInterestRate] = 0.0475;
- account[0][indexOfMonthlyPayment] = 0;
- account[1][indexOfMonthlyPayment] = 0;
- account[2][indexOfMonthlyPayment] = 0;
- account[3][indexOfMonthlyPayment] = 0;
- }
- int calcPayment(double account[4][5]) {
- double monthlyInterestRate;
- double termLengthInMonths;
- for (int i = 0; i < 4; ++i) {
- monthlyInterestRate = account[i][indexOfAnnualInterestRate] / 12.00;
- termLengthInMonths = account[i][indexOfTermInYears] * 12.00;
- //account[i][indexOfMonthlyPayment] = account[i][indexOfAmountLoaned] / (pow((1 - (1 / (monthlyInterestRate + 1))),termLengthInMonths) / monthlyInterestRate);
- account[i][indexOfMonthlyPayment] =( monthlyInterestRate + (monthlyInterestRate / (pow((1 + monthlyInterestRate),termLengthInMonths) - 1 ))) * account[i][indexOfAmountLoaned];
- }
- }
- void displayValues(double account[4][5]){
- for (int i = 0; i < 4; ++i) {
- cout << endl;
- for (int j = 0; j < 5; ++j) {
- if (j == 0) {
- cout << fixed << setprecision(0) << setw(3) << account[i][j];
- } else if(j == 1) {
- cout << setw(10) << account[i][j];
- } else if(j == 2) {
- cout << setw(8) << account[i][j];
- } else if(j ==3) {
- cout << fixed << setprecision(4) << setw(10) << account[i][j];
- } else {
- cout << fixed << setprecision(2) << setw(10) << account[i][j];
- }
- }
- }
- }
- int main() {
- double account[4][5];
- getInput(account);
- calcPayment(account);
- displayValues(account);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement