If else statement question.

Mar 29, 2016 at 9:55pm
Write your question here.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
cout << "Enter the following information about your checking account." <<
    endl << endl;

    cout << "Beginning balance: $";

    cin >> beginning_balance;

    if (beginning_balance < 0)
    {
        cout << "    You entered a negative beginning balance." << endl
             << "    your account is currently overdrawn!" << endl;
    }
    do
    {
    cout << endl;

    cout << "Number of checks written: ";

    cin >> checks_written;

    if (checks_written < 0)
    {
        cout << "    Number of checks should be zero or more" << endl
             << "    Try again." << endl;
    }

    } while (checks_written < 0);

    if ( beginning_balance < MINIMUM_MONTHLY_BALANCE && checks_written >= 1 && checks_written <= 19)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written:    " << setw(4) << checks_written << endl
              << "Low balanced fee applied:   "  << setw(4) << LOW_BALANCE_FEE << endl
              << "Check fee applied:           " << setw(4) << FIRST_CHECK_FEE << endl
              << "Monthly fee applied:        "  << setw(4) << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees:   "        << "    $ " << setw(4) << STANDARD_MONTHLY_FEE + (checks_written * FIRST_CHECK_FEE) + LOW_BALANCE_FEE << endl;
    }
    else if (beginning_balance < MINIMUM_MONTHLY_BALANCE && checks_written >= 20 && checks_written <= 39)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Low balanced fee applied: " << LOW_BALANCE_FEE << endl
              << "Check fee applied: " << SECOND_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * SECOND_CHECK_FEE) + LOW_BALANCE_FEE << endl;
    }
     else if (beginning_balance < MINIMUM_MONTHLY_BALANCE && checks_written >= 40 && checks_written <= 59)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Low balanced fee applied: " << LOW_BALANCE_FEE << endl
              << "Check fee applied: " << THIRD_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * THIRD_CHECK_FEE) + LOW_BALANCE_FEE << endl;
    }
     else if (beginning_balance < MINIMUM_MONTHLY_BALANCE && checks_written >= 60)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Low balanced fee applied: " << LOW_BALANCE_FEE << endl
              << "Check fee applied: " << FOURTH_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * FOURTH_CHECK_FEE) + LOW_BALANCE_FEE << endl;
    }
    else if (beginning_balance > MINIMUM_MONTHLY_BALANCE && checks_written >= 1 && checks_written <= 19)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Check fee applied: " << FOURTH_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * FIRST_CHECK_FEE) << endl;
    }
    else if (beginning_balance > MINIMUM_MONTHLY_BALANCE && checks_written >= 20 && checks_written <= 39)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Check fee applied: " << FOURTH_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * SECOND_CHECK_FEE) << endl;
    }
    else if (beginning_balance > MINIMUM_MONTHLY_BALANCE && checks_written >= 40 && checks_written <= 59)
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Check fee applied: " << FOURTH_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * THIRD_CHECK_FEE) << endl;

    }
    else (beginning_balance > MINIMUM_MONTHLY_BALANCE && checks_written >= 60);
    {
         fout << fixed << setprecision(2) << endl
              << "Number of checks written: " << checks_written << endl
              << "Check fee applied: " << FOURTH_CHECK_FEE << endl
              << "Monthly fee applied: " << STANDARD_MONTHLY_FEE << endl << endl
              << "Total banking fees: " << "    $ " << STANDARD_MONTHLY_FEE + (checks_written * FOURTH_CHECK_FEE) << endl;
    }
    
    cout << endl << endl;

    cout << "The bank's service fee's have been written to prog4_out.txt." << endl;

    system("PAUSE>NUL");

    return 0;
}



Why is the else statement writing to the .txt file, even if the checks_written value isn't >= 60? please help.
Mar 29, 2016 at 9:59pm
You've got a semi-colon at the end of line 90 that shouldn't be there.
Last edited on Mar 29, 2016 at 10:07pm
Mar 29, 2016 at 10:00pm
What else statement? The one on line 90? That is the only statement in the else branch.

The lines 91-97 have nothing to do with the if..else construct.


Syntax hint, there is no (condition) after else. Even if there were, the semi-colon would be an empty statement.
Mar 29, 2016 at 10:21pm
I figured out my dumb mistake, thanks guys.
Topic archived. No new replies allowed.