Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,043 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,543 people online right now. Registration is fast and FREE... Join Now!




For Loop as applied in Loan System Application

 
Reply to this topicStart new topic

For Loop as applied in Loan System Application

wingeduser
17 Jul, 2008 - 07:14 AM
Post #1

New D.I.C Head
*

Joined: 17 Jul, 2008
Posts: 1

Yeah, so this is my homework:

Objective: To learn how to write a C++ program using the for loop as applied to a loan system application.

Procedure:

1. Accept the values of the principal amount (P) and the interest rate ®.

2. Compute the Monthly Payment (MP) based on a 12-month scheme as MP = P / 12 and display this value on screen.

3. Assuming that interest is applied on a monthly diminishing balance, then display the monthly balance, monthly interest and monthly dues as follows:



Principal : 999999.99
Interest Rate (%) : 9.99
Monthly Payment : 99999.99

Month Monthly Dues Interest Balance

1
2

:

12



Here, monthly interest = [previous month’s balance * (interest rate /100)] / 12,

Monthly dues = monthly payment + monthly interest
Balance = Principal – total payments made where
Total payments made = monthly payment * number of months paid

Here's a Sample Table of computation:

Principal : 24000
Interest Rate (%) : 12%
Monthly Payment : 2000


No Due Interest Balance
24,000.00
1 2,240.00 240.00 22,000.00
2 2,220.00 220.00 20,000.00
3 2,200.00 200.00 18,000.00
4 2,180.00 180.00 16,000.00
5 2,160.00 160.00 14,000.00
6 2,140.00 140.00 12,000.00
7 2,120.00 120.00 10,000.00
8 2,100.00 100.00 8,000.00
9 2,080.00 80.00 6,000.00
10 2,060.00 60.00 4,000.00
11 2,040.00 40.00 2,000.00
12 2,000.00 20.00 -



Note that the last payment inclusive of the interest, is exactly equal to the balance. This way, we are sure that the payments made will not exceed the principal amount.

Specifications:

1. Segregate code statements by introducing void functions.

...and this is my code...

CODE
#include <iostream.h>
#include <stdio.h>
#include <conio.h>

double principal, rate, month_pay;
double balance, month_due, total_pay;
long double interest;

void input(){
    cout<<"\n\nEnter the principal amount: ";
    cin>>principal;
    cout<<"Enter monthly interest: ";
    cin>>rate;
    month_pay=principal/12;
    clrscr();
    printf("Principal : %0.2f", principal);
    cout<<"\nInterest Rate (%): ";
    printf("%0.2f", rate);
    printf("\nMonthly Payment: %0.2f", month_pay);
    }

void aaah(){
    cout<<"\n\nMonth\tMonthly Dues\tInterest\tBalance"<<endl;
    gotoxy (41,6);
    cout<<principal;

    for (int month=1, balance=principal;month<=11;month++,balance=principal-total_pay){
        total_pay=month_pay*month;
        interest=balance*(rate/100)/12;
        month_due=month_pay+interest;
        balance=principal-total_pay;
        cout<<"\n"<<month<<"\t"<<month_due<<"\t\t"<<interest<<"\t\t"<<balance;}
        interest=balance*(rate/100)/12;
        month_due=month_due-(interest*2);
        cout<<"\n12\t"<<month_due<<"\t\t"<<interest;

    }

void more(){
    cout<<"\n\nMore entries? (Y/N)";
    }

void main(){
    do{
    clrscr();
    input();
    aaah();
   cout<<"\n\nPress any key to continue";
        getch();
    more();
    if (getch()=='n')break;
    }while (principal!=0);
}


..it works fine.. if you enter 24000 and monthly interest of 12.. you get the same result as in the example.. but if you enter some values, say, 36000 and monthly interest of 12.. i got this.. there are negative numbers and that ticks me off:

Principal : 36000
Interest Rate (%) : 12%
Monthly Payment : 3000


No Due Interest Balance
36,000.00
1 2,704.64 -295.00 -32,536.00
2 2,674.64 -325.36 30,000.00
3 3,300.00 300.00 27,000.00
4 3,270.00 270.00 24,000.00
5 3,240.00 240.00 21,000.00
6 3,210.00 210.00 18,000.00
7 3,180.00 180.00 15,000.00
8 3,150.00 150.00 12,000.00
9 3,120.00 120.00 9,000.00
10 3,900.00 90.00 6,000.00
11 3,600.00 60.00 3,000.00
12 3,000.00 30.00 -


...you see how the negative interest affect the first two due payments.. i don't know why the first two interests are negative while the others are correct.. i just don't know why..

if someone can explain that.. i'll be happy!!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 04:48PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month