Need Help with an If Else Statement!!!

//Homework 3
//Gary Walker

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void main()
{
ifstream fin;
ofstream fout;
float amt = 0, bal = 0, depsum = 0, withsum = 0, newbal = 0;
int acntnum = 0, transcode = 0, depcount = 0, withcount = 0;
fin.open("C:\\Users\\Gary\\Documents\\Programming 1 files\\Bank.dat");

fout.open("hw3.doc");
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);

fin >> acntnum >> transcode >> amt >> bal;
fout << "Account Number" << setw(10) << "New Balance" << setw(30);


while (!fin.eof());

{

if (transcode == 1)

{
depcount++;
newbal = bal + amt;
fout << setw(10) << acntnum << setw(30) << newbal << endl;
depsum = depsum + amt;
fin >> acntnum >> transcode >> amt >> bal;
}
else if (transcode == 2);
{

if (amt <= bal)
{
withcount++;
newbal = bal - amt;
fout << setw(5) << acntnum << setw(35) << newbal << endl;
withsum = withsum + amt;

if (newbal < 100.00)
{
newbal = newbal - 10.00;
fout << setw(40) << "Balance is below minimum. You will be charged a 10.00 fee." << endl;
}
}
else
{
fout << setw(10) << acntnum << setw(30) << "Insufficient Funds" << endl;
}
fin >> acntnum >> transcode >> amt >> bal;
}

else
{
fout << setw(10) << accnum << setw(30) << "Bad transaction code" << endl;
fin >> accnum >> transcode >> amt >> bal;
}
}

fout << endl << "Total number of deposits made = " << depcount << endl;
fout << "Total sum of all deposits = " << depsum << endl;
fout << "Total number of successful withdrawals made = " << withcount << endl;
fout << "Total sum of all successful withdrawals = " << withsum << endl;






It's the else before the bad transaction code that is causing me problems. Says it expected a statement










}










just need to know what im doing wrong with connecting else statements to if statements
Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/
Look for extra semicolons - you have a couple at the end of statements where they shouldn't be.
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
//Homework 3
 //Gary Walker

 #include <iostream>
 #include <fstream>
 #include <iomanip>
 using namespace std;

 void main()
 {
 ifstream fin;
 ofstream fout;
 float amt = 0, bal = 0, depsum = 0, withsum = 0, newbal = 0;
 int acntnum = 0, transcode = 0, depcount = 0, withcount = 0;
 fin.open("C:\\Users\\Gary\\Documents\\Programming 1 files\\Bank.dat");

 fout.open("hw3.doc");
 fout.setf(ios::fixed);
 fout.setf(ios::showpoint);
 fout.precision(2);

 fin >> acntnum >> transcode >> amt >> bal;
 fout << "Account Number" << setw(10) << "New Balance" << setw(30);


 while (!fin.eof());

 {

 if (transcode == 1)

 {
 depcount++;
 newbal = bal + amt;
 fout << setw(10) << acntnum << setw(30) << newbal << endl;
 depsum = depsum + amt;
 fin >> acntnum >> transcode >> amt >> bal;
 }
 else if (transcode == 2);
 {

 if (amt <= bal)
 {
 withcount++;
 newbal = bal - amt;
 fout << setw(5) << acntnum << setw(35) << newbal << endl;
 withsum = withsum + amt;

 if (newbal < 100.00)
 {
 newbal = newbal - 10.00;
 fout << setw(40) << "Balance is below minimum. You will be charged a 10.00 fee." << endl;
 }
 }
 else
 {
 fout << setw(10) << acntnum << setw(30) << "Insufficient Funds" << endl;
 }
 fin >> acntnum >> transcode >> amt >> bal;
 } 

 else
 {
 fout << setw(10) << accnum << setw(30) << "Bad transaction code" << endl;
 fin >> accnum >> transcode >> amt >> bal;
 }
 }

 fout << endl << "Total number of deposits made = " << depcount << endl;
 fout << "Total sum of all deposits = " << depsum << endl;
 fout << "Total number of successful withdrawals made = " << withcount << endl;
 fout << "Total sum of all successful withdrawals = " << withsum << endl;





 }

sorry about that, i'm new here
In addition to the extra semicolons - lines 64-65 you refer to a variable accnum that isn't declared - did you mean to use acntnum ?
yes, thanks
all problems are on line 62
The compiler can't match up the else on line 62 because you have extra semicolons further up the code.
Problem solved. Can't believe I put a semicolon on a while loop....
Topic archived. No new replies allowed.