//Credit Card Interest Program
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double netBalance; //The balance shown in the bill.
double payment; //The payment made.
int d1; //The number of days of the billing cycle.
int d2; //The number of days payment is made before billing cycle.
double averageDailyBalance; //The average daily balance
double interest; //The interest on the unpaid balance
double interestRate; //The interest rate per month
cout << fixed << showpoint;
cout << "Enter the net balance: ";
cin >> netBalance;
cout << endl;
cout << "Enter the payment made: ";
cin >> payment;
cout << endl;
cout << "Enter the number of days of the billing cycle: ";
cin >> d1;
cout << endl;
cout << "Enter the number of days payment is made before billing cycle: ";
cin >> d2;
cout << endl;
cout << "Enter interest rate per month: ";
cin >> interestRate;
cout << endl;
cout << "The average daily balance is: " << (netBalance * d1 - payment * d2) / d1 << endl;
cin >> averageDailyBalance;
cout << endl;
cout << "The interest on the unpaid balance: " << averageDailyBalance * 0.0152 << endl;
cin >> interest;
cout << endl;
return 0;
}
Other than that, the end part of your code makes no sense at all. I have no idea what you are trying to achieve with the cin statements, so I can't help you with that.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double netBalance; //The balance shown in the bill.
double payment; //The payment made.
int d1; //The number of days of the billing cycle.
int d2; //The number of days payment is made before billing cycle.
double averageDailyBalance; //The average daily balance
double interest; //The interest on the unpaid balance
double interestRate; //The interest rate per month
cout << fixed << showpoint;
cout << "Enter the net balance: "; //output
cin >> netBalance; //input
cout << endl; //output
cout << "Enter the payment made: "; //output
cin >> payment; //input
cout << endl; //output
cout << "Enter the number of days of the billing cycle: "; //output
cin >> d1; //input
cout << endl; //output
cout << "Enter the number of days payment is made before billing cycle: "; //output
cin >> d2; //input
cout << endl; //output
cout << "Enter interest rate per month: "; //output
cin >> interestRate; //input
cout << endl; //output
averageDailyBalance = (netBalance * d1 - payment * d2) / d1; //The average daily balance
cout << fixed << setprecision(2); //setting the decimals
cout << "The average daily balance is: " << averageDailyBalance;
cout << endl;
cout << endl; //provide seperation between lines
interest = averageDailyBalance * interestRate; //
cout << fixed << setprecision(2); //setting the decimals
cout << "The interest on the unpaid balance: " << interest;
cout << endl;
cin.get(); //program was closing too fast; this slows it down
cin.get();
return 0;
}
Just a side note on fixed and setprecision. They will stay active until you modify cout with different manipulators, so while its fine for clarity to use multiple
cout << fixed << setprecision(2);
before each output, it's not necessary. Also, fixed mode will stay in effect until the end of the program, so if after several statements you need to remove the fixed modifier for some reason, use