خرید بک لینک

Vote count: 0

I am writing a code that tries to find out the simple and compound interest using operator overloading.

While I have found the simple interest, I am having problem with the compound interest.

#include<iostream>
#include<iomanip>

using namespace std;

class Interest
{
private:
    double P;
    double R;
    double I;
public:
    Interest(){};
    ~Interest(){};
    void setP(double recieveP){P = recieveP;}
    void setR(double recieveR){R = recieveR/100;}
    double getP(){retu P;}
    double getI(){retu I;}
    Interest operator*(int T)
    {
        class Interest int1;
        int1.I= P*R*T;
        retu int1;
    }
};

int main()
{
    class Interest simp1;
    class Interest comp1;
    double Principle,Rate,Years;
    cout << "Enter the Principle Amount" << endl;
    cin >> Principle;
    simp1.setP(Principle);
    comp1.setP(Principle);
    cout << "Enter the Rate Amount" << endl;
    cin >> Rate;
    simp1.setR(Rate);
    comp1.setR(Rate);
    cout << "Enter the number of years:";
    cin >> Years;
    simp1 = simp1*Years;
    cout << "The Simple Interest is: " << simp1.getI() << endl;
    for(int i =0; i < Years; i++)
    {
        comp1 = comp1*Years;
        comp1.setP(comp1.getI()+comp1.getP());
    }
    cout << "The compound Interest is: " << comp1.getI() << endl;

retu 0;
}

No matter what I enter the values for the compound Interest is always zero.

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 25 بهمن 1394 ساعت: 13:39

صفحه بندی