Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int indexOfAccountNumber = 0;
  10. int indexOfAmountLoaned = 1;
  11. int indexOfTermInYears = 2;
  12. int indexOfAnnualInterestRate = 3;
  13. int indexOfMonthlyPayment = 4;
  14.  
  15. int getInput(double account[4][5]) {
  16. account[0][indexOfAccountNumber] = 101;
  17. account[1][indexOfAccountNumber] = 102;
  18. account[2][indexOfAccountNumber] = 103;
  19. account[3][indexOfAccountNumber] = 104;
  20.  
  21. account[0][indexOfAmountLoaned] = 95000.00;
  22. account[1][indexOfAmountLoaned] = 100000.00;
  23. account[2][indexOfAmountLoaned] = 125000.00;
  24. account[3][indexOfAmountLoaned] = 150000.00;
  25.  
  26. account[0][indexOfTermInYears] = 15;
  27. account[1][indexOfTermInYears] = 30;
  28. account[2][indexOfTermInYears] = 30;
  29. account[3][indexOfTermInYears] = 30;
  30.  
  31. account[0][indexOfAnnualInterestRate] = 0.06875;
  32. account[1][indexOfAnnualInterestRate] = 0.055;
  33. account[2][indexOfAnnualInterestRate] = 0.045;
  34. account[3][indexOfAnnualInterestRate] = 0.0475;
  35.  
  36. account[0][indexOfMonthlyPayment] = 0;
  37. account[1][indexOfMonthlyPayment] = 0;
  38. account[2][indexOfMonthlyPayment] = 0;
  39. account[3][indexOfMonthlyPayment] = 0;
  40.  
  41. }
  42.  
  43. int calcPayment(double account[4][5]) {
  44. double monthlyInterestRate;
  45. double termLengthInMonths;
  46. for (int i = 0; i < 4; ++i) {
  47. monthlyInterestRate = account[i][indexOfAnnualInterestRate] / 12.00;
  48. termLengthInMonths = account[i][indexOfTermInYears] * 12.00;
  49.  
  50.  
  51. //account[i][indexOfMonthlyPayment] = account[i][indexOfAmountLoaned] / (pow((1 - (1 / (monthlyInterestRate + 1))),termLengthInMonths) / monthlyInterestRate);
  52. account[i][indexOfMonthlyPayment] =( monthlyInterestRate + (monthlyInterestRate / (pow((1 + monthlyInterestRate),termLengthInMonths) - 1 ))) * account[i][indexOfAmountLoaned];
  53. }
  54. }
  55.  
  56. void displayValues(double account[4][5]){
  57. for (int i = 0; i < 4; ++i) {
  58. cout << endl;
  59.  
  60. for (int j = 0; j < 5; ++j) {
  61.  
  62. if (j == 0) {
  63. cout << fixed << setprecision(0) << setw(3) << account[i][j];
  64. } else if(j == 1) {
  65. cout << setw(10) << account[i][j];
  66. } else if(j == 2) {
  67. cout << setw(8) << account[i][j];
  68. } else if(j ==3) {
  69. cout << fixed << setprecision(4) << setw(10) << account[i][j];
  70. } else {
  71. cout << fixed << setprecision(2) << setw(10) << account[i][j];
  72. }
  73. }
  74. }
  75. }
  76. int main() {
  77. double account[4][5];
  78.  
  79. getInput(account);
  80. calcPayment(account);
  81. displayValues(account);
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement