Question: How can I modify my code so that there is not a single blank line in the output, but each senetence must also begin on
How can I modify my code so that there is not a single blank line in the output, but each senetence must also begin on a different line:#include
#include
class PiggyBank
public:
stores the balanceamount of money in the piggy bank.
double balance;
Is used to store the current state of the piggy banksmashed or not, with smashed being true and not smashed being false
bool smashedState;
The default consturcotr.
PiggyBank:balancesmashedStatefalse
Parameter consructor to obtainassign the starting balance in the piggy bank.
PiggyBankdouble initialAmount:balanceinitialAmountsmashedStatefalse
If statemnt to handle the case when the balance is negative.
ifinitialAmount
std::cerr"Cannot have a negative balance of $
balance amount;
else
Seperate if stamentes that handle the indivudal conditionscases that would prevent a successful deposit,
and then prints a corresponding error message to the console.
ifsmashedState
std::cerr"Cannot deposit money into a broken bank
;
return;
ifamount
std::cerr"Cannot deposit negative
;
return;
This function is used to withdraw a specified amount of money.
void withdrawdouble amount
A withdraw will only be succesful if the piggy bank is not smashed, the amount to be withdrawn is not negative,
and the amount to be withdrawn is not greater than the amount of money in the piggy bank.
ifsmashedState&&amount &&balanceamount
balance amount;
else
Indivudal if statements that test for the different condtions that will cause a withdraw to fail, and then prints out
a coreesponding error message to the console.
ifsmashedState
std::cerr"Cannot withdraw money from a broken bank
;
return;
ifamount
std::cerr"Cannot withdraw negative
;
return;
ifamount balance
std::cerr"Cannot withdraw more money than is available
;
return;
This fucntion will smash the piggy bank when it is called.
void smash
If statement that will print an error message stating how much money was lost, but will only execute if there
was a non negative, non zero amount of money in the piggy bank.It will only print an error message if you actually lost money
ifbalance
std::cout"NOOO!!! You lost $
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
