Hi Ponvo, welcome to the forum!
There are two small problems with your code.
First, take a look at your ServiceChargeChecking constructor:
1 2 3 4
|
ServiceChargeChecking::ServiceChargeChecking()
{
int checkCount = 0;
}
|
This is creating a local integer named 'checkCount', and initializing it to zero. This is not the same 'checkCount' counter which belongs to your class, and this local 'checkCount' will cease to exist after the constructor terminates. This also leaves your actual 'checkCount' uninitialized with garbage, causing undefined behavior.
To fix this, simply get rid of the
int
, like this:
1 2 3 4
|
ServiceChargeChecking::ServiceChargeChecking()
{
checkCount = 0;
}
|
Now, this sets 'checkCount' (the actual counter that belongs to your class) to zero.
Here's the second problem, in your 'writeCheck' member function (I only need to paste the first few lines of it):
1 2 3 4 5 6 7 8 9 10 11
|
void ServiceChargeChecking::writeCheck(double checkAmt)
{
if (checkCount <= checkLimit)
{
if (checkAmt <= getBalance())
{
withdraw(checkAmt);
checkCount++;
}
}
//...
|
The problem is on line 3 of the snippet I posted. Since you're checking whether the counter is less than
OR equal to the limit (4), you will actually have a limit of 5, since you're counting from 0 - 4 inclusive.
To fix this, change line 3 from:
if (checkCount <= checkLimit)
to:
if (checkCount < checkLimit)