fork download
  1. #include <iostream>
  2.  
  3. int main() {
  4. double loan = 1000.0 , interest_paid = 0.0 , total_interest = 0.0;
  5. const double INTEREST = 0.015;
  6. const int PAYMENT = 50;
  7. int month = 0;
  8.  
  9. while( loan > 0 )
  10. {
  11. interest_paid = loan * INTEREST;
  12. total_interest += interest_paid;
  13. loan -= PAYMENT + interest_paid;
  14. ++month;
  15. }
  16. std::cout << "It took " << month << " months to pay off the loan." << std::endl;
  17. std::cout << "You paid overal $" << total_interest << " in loans." << std::endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
It took 18 months to pay off the loan.
You paid overal $132.115 in loans.