Sep 9, 2008 at 12:18pm UTC
I am having problems with my int main()...trying to get the program to enter a new balance (400.00) and then calculate a new interest (calcInt) and display it. Help!!!
#include <iostream>
#include <iomanip>
using namespace std;
//declaration
class Savings
{
double balance;
double rate;
double interest;
public:
Savings(double = 0, double = 0, double = 0);
void operator =(Savings&);
void calcInt(void); //member function to calculate interest
};
//implementation
Savings::Savings(double B, double R, double I)
{
balance = 300.00;
rate = 4.0;
interest = balance * rate/100;
}
void Savings::operator=(Savings& newFigures)
{
balance = newFigures.balance;
rate = newFigures.rate;
interest = newFigures.interest;
return;
}
void Savings::calcInt()
{
cout << "The Balance on the Savings account is: " << setw(7) << fixed << setprecision(2) << balance << endl;
cout << "The Rate on the Savings account is: " << setw(4) << fixed << setprecision(2) << rate << endl;
cout << "The Interest is: " << setw(7) << fixed << setprecision(2) << interest << endl;
return;
}
int main ()
{
cout << "\nWhen the savings amount increases to $400.00 the interest at 4 percent is: ";
a.calcInt();
return 0;
}
Sep 9, 2008 at 1:30pm UTC
1. Please use code tags. They can be found by clicking the # symbol on the format bar to the right of the text box.
2. You never declared "a" as type Savings, so you need to add
Savings a;
at the top of your main.
Sep 10, 2008 at 5:03am UTC
if using
Add one more constructor "Savings()" to initialize the object to default vaue.
or
declare the object as
Savings a(<B value>,<R value>,<I value>);
Moreover, why do you want to pass the interest as parameter,since you are calculating it with other 2 parameters.
Last edited on Sep 10, 2008 at 5:03am UTC