Hello, so this is my assignment:
A bank charges $10 per onth plus the following check fees for a commercial checking account:
$.10 each for fewer than 20 checks
$.08 each for 20-39 checks
$.06 each for 40-59 checks
$.04 each for 60 or more checks
the bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of checks written. Compute and display the bank's service fees for the month.
input validation: do not accept a negative value for the number of cheks written. if a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn.
//
// main.cpp
// Bank Charges
//
// Created by Perry Lindo on 4/10/14.
// Copyright (c) 2014 Perry Lindo. All rights reserved.
//
#include <iostream>
#include <iomanip>
#include <cstdlib>
#define MONTHLY 10
#define NEGBAL 15
usingnamespace std;
int main()
{
system("CLS");
double first , second , third , fourth , totalfee;
double fee1 = .10, fee2 = .08, fee3 = .06, fee4 = .04;
int checks, bal;
cout << "Please enter your account balance:";
cin >> bal;
cout << "Please enter the amount of checks you wrote this month: ";
cin >> checks;
while (checks < 0)
{
cout << "\n\nChecks must be greater than 0.\n\n";
cout << "Please re-enter a positive amount of checks you wrote this month: ";
cin >> checks;
}
if (checks <= 20)
first = (checks * fee1);
elseif (checks >= 21 && checks <= 39)
second = (checks * fee2) + first;
elseif (checks >= 40 && checks <= 59)
third = (checks * fee3) + first + second;
else
fourth = (checks * fee4) + first + second + third;
totalfee = (MONTHLY + first + second + third + fourth);
if (bal <= 399)
totalfee = (MONTHLY + first + second + third + fourth) - NEGBAL;
cout << "\n\n";
cout << "Your total fee is $" << totalfee << endl;
cin.clear();
cin.sync();
cin.get();
return 0;
}
if (checks <= 20)
first = (checks * fee1);
elseif (checks >= 21 && checks <= 39)
second = (checks * fee2) + first;
elseif (checks >= 40 && checks <= 59)
third = (checks * fee3) + first + second;
else
fourth = (checks * fee4) + first + second + third;
only one of the if/else statements will be called no matter the number of checks.
I'm not really sure what you intend this section to do. If it is a flat fee dependent on the number of checks it would be best to use if/else statements starting with the highest number of checks and checking the next bracket down from there.
Okay a few things,
You shouldn't use C style defines for constants (referring to MONTHLY and NEGBAL) Google "static const vs define" checks >= 21 and checks >= 40 are redundant. If checks not less than or equal to twenty it _must_ be greater than or equal to 21. You don't need to check both conditions.
More importantly, you're using uninitialized values:
[edit: ninja'd by RadWayne, I agree with him]
line 42, first hasn't been initialized
line 44, first and second haven't been initialized
line 46, first, second, and third haven't been initialized
line 47, the only value that could have been initialized is first, and that's only if checks is less than or equal to 21
same goes for 49