Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tchar.h>
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main()
- {
- double loan;
- double interest;
- double payment;
- std::cout << std::setprecision(2);
- cout << "This program is a loan calculation program. \n";
- cout << "What is your desired loan amount? $ \n";
- cin >> loan;
- cout << "What is the interest rate on this loan? Please express this with a decimal number.";
- cin >> interest;
- cout << "What is your desired monthly payment? $ \n";
- cin >> payment;
- while (payment < loan * interest / 12){
- cout << "That isn't enough to ever pay off your loan. Please try again and make it a number higher than $";
- cout << (loan*interest / 12);
- exit(0);
- }
- double totalpaid = 0.0;
- double moreinterest= 0.0;
- int months=0;
- double remaining = loan;
- double add=0.0;
- cout << "Month : Loan Balance: Interest Added, Amount Paid, Debt Remaining \n";
- while (remaining > 0) {
- moreinterest = remaining * interest / 12;
- months++;
- remaining += moreinterest;
- if (remaining > payment){
- add = payment;
- }
- else {
- add = remaining;
- }
- totalpaid += add;
- remaining -= add;
- cout << months << " $" << loan << " $" << moreinterest << " $" << add << " $" << remaining << endl;
- }
- cout << endl << "Here's your loan information. \n";
- cout << "Initial Loan: $" << loan << endl;
- cout << "Total amount paid: $" << totalpaid << endl;
- cout << "Time to pay off loan: " << months << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment