had a weird error and fix???

So, I was finishing up my code to my ledger that calculates a running total on a set of transactions and I got to my last else statement and it told that I needed a ";" before the "{" which I thought was weird because I have never done that before. So I put the ";" right before the "{" and the code runs perfectly fine. Can anyone explain this??
1
2
3
4
else (NewBalance > 10000); {
        intRate = .05 * NewBalance;
        cout << "You have earned $" << intRate << " in interest at 5%" << endl;
                } 
The actual error is probably somewhere else in your code before that point. You were correct, a semicolon does not normally go there.
Here is my whole code if anyone can figure out where I may have went wrong... I am getting an error when I run this program. When I run this it will output that last else statement even if say the total is 6000 and not over 10000 like I am telling it to do.

Any help??

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
#include <iostream>

using namespace std; 
char Transaction;
double NewBalance=0;

int main() {
	
	double begin, first, second, third, intRate;
	
	cout << "Enter your beginning balance: " << endl;
	cin >> begin;
	NewBalance=begin;

	cout << "Use the letter D for deposit or W for withdrawal" << endl;
	cout << "Enter your first transaction: " << endl;
	cin >> Transaction >> first;

	if (Transaction=='W')
		{NewBalance=NewBalance-first;}
	else if (Transaction=='D')
		{NewBalance=NewBalance+first;}
	
	cout << "Enter your second transaction: " << endl;
	cin >> Transaction >> second;
	
	if (Transaction=='W')
		{NewBalance=NewBalance-second;}
	else if (Transaction=='D')
		{NewBalance=NewBalance+second;}
		
	cout << "Enter your third transaction: " << endl;
	cin >> Transaction >> third;
	
	if (Transaction == 'W')
		{NewBalance=NewBalance-third;}
	else if (Transaction == 'D')
		{NewBalance=NewBalance+third;}
		

	cout << "Current Balance: \t" << NewBalance << endl;
	
	if (NewBalance < 1000) {
       intRate = .02 * NewBalance;
       cout << "You have earned $" << intRate << " in interest at 2%" << endl;
                   }
	else if ((NewBalance >= 1000) && (NewBalance < 5000)) {
       intRate = .03 * NewBalance;
       cout << "You have earned $" << intRate << " in interest at 3%" << endl;
                   }
 	else if ((NewBalance >= 5000) && (NewBalance < 10000)) {
       intRate = .04 * NewBalance;
       cout << "You have earned $" << intRate << " in interest at 4%" << endl;
                   }
    else (NewBalance >= 10000); {
        intRate = .05 * NewBalance;
        cout << "You have earned $" << intRate << " in interest at 5%" << endl;
                } 
	
	system("PAUSE");
	
	return 0;
	
}
I'm a bozo. The final "else" is a default, you aren't supposed to have a condition after it.
wow ... I can't believe I forgot about that...

Thank you for the help computergeek!
Topic archived. No new replies allowed.