Advertisement
Slyfoxx724

p3.c

Dec 7th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. 1 #include <stdio.h>
  2. 2 int main (void)
  3. 3 {
  4. 4 double loan_amount, loan_balance, total_interest;
  5. 5 double monthly_payment, monthly_interest_rate;
  6. 6 double interest_rate, interest_for_this_month, left_over_payment;
  7. 7
  8. 8 int years, month;
  9. 9
  10. 10 printf("How many years is your loan?: ");
  11. 11 scanf("%i", &years);
  12. 12
  13. 13 printf("Loan amount?: ");
  14. 14 scanf("%lf", &loan_amount);
  15. 15
  16. 16 printf("Annual interest rate in percent?: ");
  17. 17 scanf("%lf", &interest_rate);
  18. 18
  19. 19 printf("Monthly payment?: ");
  20. 20 scanf("%lf", &monthly_payment);
  21. 21
  22. 22 /* years = 30;
  23. 23 loan_amount = 200000;
  24. 24 interest_rate = 6;
  25. 25 monthly_payment = 1199.10;
  26. 26 */
  27. 27 monthly_interest_rate = interest_rate/100/12;
  28. 28 total_interest = 0.0;
  29. 29 loan_balance = loan_amount;
  30. 30
  31. 31 for(month = 1; month <= years*12; month++)
  32. 32 {
  33. 33 interest_for_this_month = monthly_interest_rate*loan_balance;
  34. 34 total_interest = total_interest + interest_for_this_month;
  35. 35 left_over_payment = monthly_payment - interest_for_this_month;
  36. 36 loan_balance = loan_balance - left_over_payment;
  37. 37
  38. 38 printf("Month(%i) interest = %10.2lf, left_over_payment = %1 0.2lf, balance = %10.2lf\n", month, interest_for_this_month, left_over_paymen t, loan_balance);
  39.  
  40.  
  41. 40 }
  42. 41 printf("Total Interest = %10.2f,\t", total_interest);
  43. 42 printf("Final Balance = %7.2f\n", loan_balance);
  44. 43 return 0;
  45. 44 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement