can anyone help me? i got problem count the monthly installment.

//class
class vehicle
{
    public:
    char model[20], color[20], brand[20];
    float price, deposit, rate, monthly_installment, newprice;
    int term;

    public:
    void calculate_installment();
};

class car:public vehicle
{
    private:
    float installment, newprice;

    public:
    void calculate_installment();
};

//main program

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include "classvehicle.h"

using namespace std;

int main()
{
    vehicle vehicle1;
    car car1;  

    vehicle1.calculate_installment();
    car1.calculate_installment();
    //system ("PAUSE"); 
}

void vehicle::calculate_installment()
{
    cout<<"\n Program to calculate car price:";
    cout<<"\n Model:";
    cin>>model;
    cout<<"\n Color:";
    cin>>color;
    cout<<"\n Brand:";
    cin>>brand;
    cout<<"\n Program to calculate new price of car:";
    cout<<"\n Price of car :";
    cin>>price;
    cout<<"\n Deposit:";
    cin>>deposit;   
    newprice = price - deposit;
    cout<<"\n The new price of car is :" <<newprice<<endl; 
}

void car::calculate_installment()
{   

    cout<<"\n Program to new price installment:";
    cout<<"\n Rate of car :";
    cin>>rate;
    cout<<"\n Term of car:";
    cin>>term;  
    installment= newprice+(rate*term);
    cout<<"\n The new price installment is :" <<installment<<endl;
    monthly_installment = installment/(term*12);
    cout<<"\n The montly installment that have to pay is :" <<monthly_installment <<endl; 
}
//class
class vehicle
{
    protected:
    char model[20], color[20], brand[20];
    float price, deposit, rate, monthly_installment, newprice;
    int term;

    public:
    void calculate_installment();
};

class car:public vehicle
{
    private:
    float installment; //newprice removed since provided by vehicle

    public:
    void calculate_installment();
};

//main program

#include <iostream>
#include <string.h> //Use cstdio instead
#include <stdlib.h> //Use cstdlib instead
//#include "classvehicle.h"

using namespace std;

int main()
{
    //vehicle vehicle1; //You can add this back if you really want it.
    car car1;  

    //vehicle1.calculate_installment(); // See above.
    car1.calculate_installment();
    //system ("PAUSE"); 
}

void vehicle::calculate_installment()
{
    cout<<"\n Program to calculate car price:";
    cout<<"\n Model:";
    cin>>model;
    cout<<"\n Color:";
    cin>>color;
    cout<<"\n Brand:";
    cin>>brand;
    cout<<"\n Program to calculate new price of car:";
    cout<<"\n Price of car :";
    cin>>price;
    cout<<"\n Deposit:";
    cin>>deposit;   
    newprice = price - deposit;
    cout<<"\n The new price of car is :" <<newprice<<endl; 
}

void car::calculate_installment()
{   
    vehicle::calculate_installment();
    cout<<"\n Program to new price installment:";
    cout<<"\n Rate of car :";
    cin>>rate;
    cout<<"\n Term of car:";
    cin>>term;  
    installment= newprice+(rate*term); //THIS LINE IS WRONG
    cout<<"\n The new price installment is :" <<installment<<endl;
    monthly_installment = installment/(float)(term*12); //Added (float) for sanity's sake 
    cout<<"\n The montly installment that have to pay is :" <<monthly_installment<<endl; 
}

Disclaimer: I apologize for my poor English. I am, unfortunately, American.
This is mostly working code. But it is still wrong. Really, you should rewrite it so that it asks for the information in a different member function like get_vehicle_info() or something. Then call calculate_installment().

Lastly, that line I marked as wrong? It's wrong as the day is long. If you're inputting the rate as a percentage, then it needs to be divided by 100. Otherwise, if it's in the form of 0.04 as in %4, it's fine.

Now, add that to 1. (%4 would become 1.04)
Then you need to raise that number to power of your term. Use the pow function in cmath.
Then multiply that by the new price to get the "final price" or what you've called the "installment."

But if you really want to be accurate, use this:
http://en.wikipedia.org/wiki/Compound_interest#Monthly_mortgage_payments

Happy coding.

This article has been dead for over six months. Start a new discussion instead.