Code: Select all
// Program4.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int bankcharge=10;
double balance;
int checks;
double checkfee;
int bankfee=0;
// above declares all the variables that will be used. bankfee is set to 0 so that
// later when we do a check we don't get a compiler warning for using an
// undefined variable.
cout << "What is the beginning balance of your bank account?";
cin >> balance;
//accepts input from the user.
if (balance < 0)
{
cout << "\nYour account is overdrawn and your bank\n";
cout << "account has been closed. We apologize for any\n";
cout << "inconvience this might have caused. Put more money\n";
cout << "in your account.\n\n";
return 0;
}
// essentially tells the customer that their account is overdrawn and the
// bank closed their account because of this. It also ends the program
// there is no point in continuing since they don't have money
// to be writing checks anyways.
cout << "How many checks did you write?";
cin >> checks;
//accepts user input, begin error checking below.
while (checks < 0)
{
cout << "\nError: Please enter a positive number:";
cin >> checks;
}
cout << "\n"; // simply for formatting reasons.
// the above loop ensures that the user enters a positive value
// below begins some checks to determine user check fee.
if (checks < 20)
{
checkfee=0.10;
}
else if( checks < 40 )
{
checkfee=0.08;
}
else if ( checks < 60 )
{
checkfee=0.06;
}
else
{
checkfee=0.04;
}
balance= balance-bankcharge;
// determines the users current balance. we don't want to charge them
// the bankfee for account being below 400 after we add in check fees
// however, it did not say anything about bank charges being applied.
if (balance < 400 )
{
bankfee=15;
}
double totalcheckfee=checks*checkfee;
balance=balance-bankfee-totalcheckfee;
// calculates the final balance.
if (bankfee==15)
{
cout << "You were charged a $15.00 fee for falling below $400.00 .\n";
}
//above code just displays that fee if it was applied, else it's not displayed.
cout << setprecision(2) << fixed;
cout << "You were charged $"<< totalcheckfee << " in check fees.\n";
cout << "You were also charged the standard $10.00 fee for having an account.\n";
cout << "Your ending balance at the end of"; // new line left off on purpose
cout << "the month is $"<<balance << ".\n";
return 0;
}