I'm working through an exercise.
I got it working so that the constructor / get and set function all
work. Now I'm trying to create a new function that will change the
value, here is what I have at the moment:
#include <iostream>
using std::cout;
using std::endl;
#include "account.h"
// constructor initializes accountBalance with int supplied as argument
Account::Account( int Balance )
{
setAccountBalance( Balance );
}
// function to set the account balance
void Account::setAccountBalance( int Balance )
{
if (Balance 0)
accountBalance = Balance;
if (Balance <= 0)
{
accountBalance = 0;
cout << "You cannot have a negative balance - reset to 0" <<
endl;
} //end if statement
}
// function to get the course name
int Account::getAccountBalance()
{
return accountBalance;
}
// display the current balance
void Account::current()
{
cout << "The current balance is: " << getAccountBalance() << endl;
}
------------------------------------------------------------------------------------------
The function I'm having trouble with is the credit(). Can someone talk
me through what should be happening here.
I have the following code in main.cpp file.
balance1.credit( 10 );
This I believe should call the credit function of object1 and pass it
an integer value of 10. The function below then needs to take this
value of 10 add it to the overall balance. So do I just add amount to
int Balance ? Also I'm not sure to what function I should be returning
the value to ?
// credit the account
int Account::credit ( int amount )
{
}