Infallible

Untitled

Sep 24th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double paymentCheck (double, double);
  5. double totalPaid (double, double, double);
  6.  
  7. int main() {
  8.     double loan = 0, loanTwo, rate = 0, rateTwo = 0, payment = 0, paymentTwo = 0, total = 0, totalTwo = 0;
  9.     cout<<"What is the loan amount of the first loan, the annual interest rate, and the monthly payment? \n";
  10.     cin>> loan >> rate >> payment;
  11.     while(paymentCheck(loan, rate) > payment){
  12.             cout<<"The monthly payment is too low. Enter a higher amount. \n";
  13.             cin>> payment;
  14.         }
  15.     total = totalPaid(loan, rate, payment);
  16.     cout<< "\n";
  17.     cout<<"What is the loan amount of the second loan, the annual interest rate, and monthly payments? \n";
  18.     cin>> loanTwo >> rateTwo >> paymentTwo;
  19.    
  20.     while(paymentCheck(loanTwo, rateTwo) > paymentTwo){
  21.             cout<<"The monthly payment is too low. Enter a higher amount. \n";
  22.             cin>> paymentTwo;
  23.         }
  24.     totalTwo = totalPaid(loanTwo, rateTwo, paymentTwo);
  25.     cout<<"\n";
  26.    
  27.     if (loan > loanTwo){
  28.         cout<<"Difference between the two loans is " << (loan-loanTwo) << " with the first loan being the bigger amount. (" << loan << " vs " << loanTwo << ") \n";
  29.         } else if (loan < loanTwo){
  30.             cout<<"Difference between the two loans is " << (loanTwo-loan) << " with the second loan being the bigger amount. (" << loan << " vs " << loanTwo << ") \n";
  31.             } else {
  32.                 cout<<"The loans are the same amount. (" << loan << " vs " << loanTwo << ") \n";
  33.     }
  34.    
  35.     if (rate > rateTwo){
  36.         cout<<"Difference between the two rates is " << (rate-rateTwo) << " with the first rate being the bigger amount. (" << rate << " vs " << rateTwo << ") \n";
  37.         } else if (rate < rateTwo){
  38.             cout<<"Difference between the two rates is " << (rateTwo-rate) << " with the second rate being the bigger amount. (" << rate << " vs " << rateTwo << ") \n";
  39.             } else {
  40.                 cout<<"The rates are the same amount. (" << rate << " vs " << rateTwo << ") \n";
  41.     }
  42.    
  43.     if (payment > paymentTwo){
  44.         cout<<"Difference between the two payment is " << (payment-paymentTwo) << " with the first payment being the bigger amount. (" << payment << " vs " << paymentTwo << ") \n";
  45.         } else if (payment < paymentTwo){
  46.             cout<<"Difference between the two payments is " << (paymentTwo-payment) << " with the second payment being the bigger amount. (" << payment << " vs " << paymentTwo << ") \n";
  47.             } else {
  48.                 cout<<"The payments are the same amount. (" << payment << " vs " << paymentTwo << ") \n";
  49.     }
  50.    
  51.     cout<< "This is what you pay in total for the first loan. : " << total << " \n" << "This is what you pay for in total for the second loan. : " << totalTwo << " \n";
  52.    
  53.     if (total > totalTwo){
  54.         cout<<"Difference between the two totals is " << (total-totalTwo) << " with the first total being the bigger amount. (" << total << " vs " << totalTwo << ") \n";
  55.         } else if (total < totalTwo){
  56.             cout<<"Difference between the two total is " << (totalTwo-total) << " with the second total being the bigger amount. (" << total << " vs " << totalTwo << ") \n";
  57.             } else {
  58.                 cout<<"The totals are the same amount. (" << total << " vs " << totalTwo << ") \n";
  59.     }
  60.     return 0;
  61. }
  62.  
  63. double paymentCheck (double loan, double rate){
  64.     double interest = ((rate/100) / 12) * loan;
  65.     return interest;
  66. }
  67.  
  68. double totalPaid (double loan, double rate, double payment){
  69.     double amount = 0;
  70.     double monthlyRate = (rate/100) / 12;
  71.    
  72.     while (loan >= payment){
  73.         loan = ((loan * monthlyRate) + loan) - payment;
  74.         amount = amount + payment;
  75.         }
  76.         amount = amount + loan;
  77.     return amount;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment