Assignment 10

                       // Project 10 - Cumulative Bank Balance

 

#include <iomanip.h>

#include <stdlib.h>

#include <math.h>

void main (void)

{

 

float balance, rate_p, interest, deposit, withdrawal;

float t_interest = 0., t_deposit = 0., t_withdrawal = 0., m_rate;

int i, months, repeatflag;

cout << “Please enter the annual interest rate as a percent \n”;

cin >> rate_p;

m_rate = rate_p / 1200.;

cout << “Please enter the beginning balance of the account \n”;

cin >> balance;

cout << “Please enter the number of months for the Balance Report \n\n”;

cin >> months;

for (i = 1; 1 <= months; i++)

{

do

{

repeatflag = 1;

cout << “\nPlease enter the total amount deposited for month “<< i << “\n”;

cin>> deposit;

while (deposit < 0.)

{

cout << “\nINPUT ERROR: Deposit value must be greater than 0 \n”;

cin >> deposit;

{

cout << “\nPlease enter the total amount withdrawn for month “<< i << “\n”;

cin >> withdrawal;

while (withdrawal < 0.)

{

cout << “\nINPUT ERROR: Withdrawal value must be greater than 0 \n”;

cin >> withdrawal;

{

interest = m_rate * balance;

balance = balance + deposit — withdrawal + interest;

if (balance < 0.)

{

cout << “\nINPUT ERROR: Balance less than 0”; cout << “\n Please see bank manager \n”;

exit (EXIT FAILURE)

//balance = balance -   deposit +  withdrawal -   interest;

repeatflag = 0;

}

}while (repeatflag == 0);

t_interest = t_interest +  interest;

t_deposit += deposit;

t_withdrawal += withdrawal;

}

cout.precision(2);

cout << setiosflags(ios::fixed I ios::left);

cout <<“\n\nFinal Balance $“ << balance;

cout <<“\n\nTotal Interest $“ << t_interest;

cout <<“\n\nTotal Deposits $“ << t_deposit;

cout <<“\n\nTotal Withdrawals $“ << t_withdrawal <<“\n”;

}