Guest User

Untitled

a guest
Mar 26th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <tchar.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. double loan;
  10. double interest;
  11. double payment;
  12. std::cout << std::setprecision(2);
  13.  
  14. cout << "This program is a loan calculation program. \n";
  15. cout << "What is your desired loan amount? $ \n";
  16. cin >> loan;
  17. cout << "What is the interest rate on this loan? Please express this with a decimal number.";
  18. cin >> interest;
  19. cout << "What is your desired monthly payment? $ \n";
  20. cin >> payment;
  21. while (payment < loan * interest / 12){
  22. cout << "That isn't enough to ever pay off your loan. Please try again and make it a number higher than $";
  23. cout << (loan*interest / 12);
  24. exit(0);
  25. }
  26. double totalpaid = 0.0;
  27. double moreinterest= 0.0;
  28. int months=0;
  29. double remaining = loan;
  30. double add=0.0;
  31.  
  32. cout << "Month : Loan Balance: Interest Added, Amount Paid, Debt Remaining \n";
  33. while (remaining > 0) {
  34. moreinterest = remaining * interest / 12;
  35. months++;
  36. remaining += moreinterest;
  37. if (remaining > payment){
  38. add = payment;
  39. }
  40. else {
  41. add = remaining;
  42. }
  43. totalpaid += add;
  44. remaining -= add;
  45.  
  46. cout << months << " $" << loan << " $" << moreinterest << " $" << add << " $" << remaining << endl;
  47. }
  48. cout << endl << "Here's your loan information. \n";
  49. cout << "Initial Loan: $" << loan << endl;
  50. cout << "Total amount paid: $" << totalpaid << endl;
  51. cout << "Time to pay off loan: " << months << endl;
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment