Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1336-001
- //Calculates the interest on a persons credit card.
- //January 15, 15
- #include <iostream>
- #include <iomanip>
- using namespace std;
- //Prototypes
- double averageDailyBalanceFunction(double, double, int, int); // Calculates the users average daily balance.
- double interestFunction(double, double); // The interest that is added after every cycle.
- void displayFunction(double, double, int, int, double, double, double); // Displays all of the inputs and calculated data.
- int main()
- {
- double averageDailyBalance = 0.0; // Calculates the users average daily balance.
- double netBalance = 0.0; // Users current account balance.
- double payment = 0.0; // Payment amount this cycle.
- int d1 = 0; // Number of days in the billing cycle.
- int d2 = 0; // Number of days payment is made before billing cycle.
- double interest = 0.0; // Interest that is added this cycle.
- double monInterestRate = 0.0; // The monthly interest rate.
- for (int counter = 0; counter < 3; counter++)
- {
- cout << "Please enter your current balance. " << endl << "$";
- cin >> netBalance;
- cout << "Please enter your desired payment. " << endl << "$";
- cin >> payment;
- cout << "Please enter the number of days in the billing cycle. " << endl;
- cin >> d1;
- cout << "Please enter the number of days payment is made before the billing cycle. " << endl;
- cin >> d2;
- cout << "What is the monthly interest rate? (ex. 1.62) " << endl;
- cin >> monInterestRate;
- monInterestRate = monInterestRate / 100;
- averageDailyBalance = averageDailyBalanceFunction(netBalance, payment, d1, d2);
- // Sets the variable 'interest' to the return value from 'interestFunction'.
- interest = interestFunction(averageDailyBalance, monInterestRate);
- displayFunction(netBalance, payment, d1, d2, monInterestRate, averageDailyBalance, interest);
- }
- system("pause");
- return 0;
- }
- // Calculates the users average daily balance.
- double averageDailyBalanceFunction(double netBalance, double payment, int d1, int d2)
- {
- double averageDailyBalance; // Calculates the users average daily balance.
- averageDailyBalance = (netBalance * d1 - payment * d2) / d1;
- return averageDailyBalance;
- }
- // The interest that is added this cycle.
- double interestFunction(double averageDailyBalance, double monInterestRate)
- {
- return (averageDailyBalance * monInterestRate);
- }
- // Displays all of the inputs and calculated data.
- void displayFunction(double netBalance, double payment, int d1, int d2, double monInterestRate,
- double averageDailyBalance, double interest)
- {
- cout << fixed << setprecision(2); // Sets the decimal place to spots behind the zero.
- cout << "Your new current balance is $" << netBalance << endl << endl;
- cout << "Your last payment was $" << payment << endl << endl;
- cout << "The days in your billing cycle are " << d1 << endl << endl;
- cout << "The number of days you paid before the billing date was " << d2 << endl << endl;
- cout << "Your average daily balance is $" << averageDailyBalance << endl << endl;
- cout << "Your current interest is $" << interest << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment