steamengines

PA 2 Credit Card Interest

Jan 20th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1336-001
  3. //Calculates the interest on a persons credit card.
  4. //January 15, 15
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. //Prototypes
  11. double averageDailyBalanceFunction(double, double, int, int); // Calculates the users average daily balance.
  12. double interestFunction(double, double); // The interest that is added after every cycle.
  13. void displayFunction(double, double, int, int, double, double, double); // Displays all of the inputs and calculated data.
  14.  
  15.  
  16. int main()
  17. {
  18.  
  19.     double averageDailyBalance = 0.0; // Calculates the users average daily balance.
  20.     double netBalance = 0.0; // Users current account balance.
  21.     double payment = 0.0; // Payment amount this cycle.
  22.     int d1 = 0; // Number of days in the billing cycle.
  23.     int d2 = 0; // Number of days payment is made before billing cycle.
  24.     double interest = 0.0; // Interest that is added this cycle.
  25.     double monInterestRate = 0.0; // The monthly interest rate.
  26.  
  27.     for (int counter = 0; counter < 3; counter++)
  28.     {
  29.         cout << "Please enter your current balance. " << endl << "$";
  30.         cin >> netBalance;
  31.  
  32.         cout << "Please enter your desired payment. " << endl << "$";
  33.         cin >> payment;
  34.  
  35.         cout << "Please enter the number of days in the billing cycle. " << endl;
  36.         cin >> d1;
  37.  
  38.         cout << "Please enter the number of days payment is made before the billing cycle. " << endl;
  39.         cin >> d2;
  40.  
  41.         cout << "What is the monthly interest rate? (ex. 1.62) " << endl;
  42.         cin >> monInterestRate;
  43.         monInterestRate = monInterestRate / 100;
  44.  
  45.         averageDailyBalance = averageDailyBalanceFunction(netBalance, payment, d1, d2);
  46.  
  47.         // Sets the variable 'interest' to the return value from 'interestFunction'.
  48.         interest = interestFunction(averageDailyBalance, monInterestRate);
  49.  
  50.         displayFunction(netBalance, payment, d1, d2, monInterestRate, averageDailyBalance, interest);
  51.     }
  52.  
  53.  
  54.     system("pause");
  55.     return 0;
  56. }
  57.  
  58. // Calculates the users average daily balance.
  59. double averageDailyBalanceFunction(double netBalance, double payment, int d1, int d2)
  60. {
  61.     double averageDailyBalance; // Calculates the users average daily balance.
  62.     averageDailyBalance = (netBalance * d1 - payment * d2) / d1;
  63.         return averageDailyBalance;
  64. }
  65.  
  66. // The interest that is added this cycle.
  67. double interestFunction(double averageDailyBalance, double monInterestRate)
  68. {
  69.  
  70.     return (averageDailyBalance * monInterestRate);
  71. }
  72.  
  73. // Displays all of the inputs and calculated data.
  74. void displayFunction(double netBalance, double payment, int d1, int d2, double monInterestRate,
  75.                      double averageDailyBalance, double interest)
  76. {
  77.     cout << fixed << setprecision(2); // Sets the decimal place to spots behind the zero.
  78.     cout << "Your new current balance is $" << netBalance << endl << endl;
  79.     cout << "Your last payment was $" << payment << endl << endl;
  80.     cout << "The days in your billing cycle are " << d1 << endl << endl;
  81.     cout << "The number of days you paid before the billing date was " << d2 << endl << endl;
  82.     cout << "Your average daily balance is $" << averageDailyBalance << endl << endl;
  83.     cout << "Your current interest is $" << interest << endl << endl;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment