Author Topic: Total Interest  (Read 3318 times)

louiecerv

  • Moderator
  • User
  • *****
  • Posts: 85
Total Interest
« on: November 24, 2005, 06:45:30 PM »
To view the text of the problem, visit the class yahoo groups site.

Code: [Select]

#include <iostream>

using namespace std;

int main()
{
    cout << "-- TOTAL INTEREST --" << endl << endl;
   
    float price, annualRate, monthlyRate, payment;
    const int MONTHS_IN_YR = 12;
   
    cout << "Price                    :  ";
    cin >> price;
    cout << "Annual Interest Rate (%) :  ";
    cin >> annualRate;
    cout << "Monthly Payment          :  ";
    cin >> payment;
   
    monthlyRate = annualRate / MONTHS_IN_YR;
   
    float interest = 0, totalInterest = 0;
    float balance = price;
    int months = 0;
   
    while (balance > 0)
    {
        interest = balance * monthlyRate / 100;            
        balance  -= (payment-interest);
        months++;
        totalInterest += interest;
    }
   
    cout << "Total Interest paid     :  " << totalInterest << endl;
    cout << "Months until paid up    :  " << months << endl;
   
    system("PAUSE");
    return 0;
}
Analyze. Design. Develop. Debug. Deploy. Maintain.