assign4 - m_int = (y_int/12)/100; cout...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <iomanip> # using namespace std; u int main() { //define variables double pmt; //monthly payment double prin; //principal amount double newprin; //updated principal amount after each payment double m_int; //interest rate per month double y_int; //interest rate per year int month = 0; //number of months //input initial loan amount cout << "Loan amount: "; cin >> prin; cout << endl; //input yearly interest rate cout << "Interest rate per year (as a percentage): "; cin >> y_int; cout << endl; //convert yearly interest rate to monthly interest rate
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: m_int = (y_int/12)/100; cout &lt;&lt; &quot;m_int = &quot; &lt;&lt; m_int &lt;&lt; endl; //input monthly payment cout &lt;&lt; &quot;Monthly payment: &quot;; cin &gt;&gt; pmt; cout &lt;&lt; endl; if (pmt &lt; m_int * prin) { cout &lt;&lt; &quot;Your monthly payment is too low.&quot; &lt;&lt; endl; cout &lt;&lt; &quot;Thus, the loan amount can't be repaid.&quot; &lt;&lt; endl; } else { while (prin &gt; 0) { newprin = prin - pmt + m_int * prin; prin = newprin; month++; cout &lt;&lt; month &lt;&lt; endl; cout &lt;&lt; &quot;New principle = &quot; &lt;&lt; newprin &lt;&lt; endl; } cout &lt;&lt; &quot;Total months needed to pay off loan: &quot; &lt;&lt; month &lt;&lt; endl; } return 0; }...
View Full Document

This note was uploaded on 11/29/2010 for the course CS CS 102 taught by Professor Topham during the Summer '10 term at Ohlone.

Ask a homework question - tutors are online