Just revision required

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.

can someone revise this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 //
//  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

using namespace 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);
	else if (checks >= 21 && checks <= 39)
		second = (checks * fee2) + first;
	else if (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;
    
    }
Are you simply asking for a code review or is there a problem with the code? [edit: sorry missed the heading]
Last edited on
this section does not do what you intend:

1
2
3
4
5
6
7
8
 if (checks <= 20)
		first = (checks * fee1);
	else if (checks >= 21 && checks <= 39)
		second = (checks * fee2) + first;
	else if (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
Last edited on
Mcpilf, as a beginner, I go for the simplest maths my brain can handle, if this is any help!
Good luck - Donnie from Down Under

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <iomanip>
using namespace std;
int main()

{   double fee;
	int checks, bal;
    cout << "Please enter your account balance: $";
    cin >> bal;
    {if (bal < 0)
    cout << "\nURGENT MESSAGE: Your account is overdrawn. Please deposit funds immediately!\n";
    }
    cout << "\nPlease enter the number of checks you wrote this month: ";
	cin >> checks;

    while (checks < 0)
    {	cout << "\nChecks must be greater than 0.\n\n";
		cout << "Please re-enter a positive number of checks you wrote this month: ";
		cin >> checks; }

    {if (checks <20)
		fee = checks * .10;
	else if (checks >= 20 && checks <40)
		fee = checks * .08;
	else if (checks >= 40 && checks < 60)
		fee = checks * .06;
	else fee = checks * .04;}

    {if (bal < 400)
   	cout << setprecision (2)<<fixed<<"\nYour total monthly fee is: $" << 10 + fee + 15 ;
	else cout << setprecision (2)<<fixed<<"\nYour total monthly fee is: $" << 10 + fee;}

	cin.clear();
	cin.sync();
	cin.get();
    return 0;
    }

Mcpilf, as a beginner, I go for the simplest maths my brain can handle, if this is any help!
Good luck - Donnie from Down Under


Hi Donnie, that's a nice program you built. the thing is that my instructor had some additional requirements I failed to specify:

*Use symbolic constants for the bank charges:
#define MONTHLY 10
#define NEGBAL 15

*The program must clear the display screen before displaying its first line of output.

that's why i had those symbolic constants at the top. but an excellent program further, i saw how it's SUPPOSED to work, haha
Topic archived. No new replies allowed.