If/Else clauses

I am having trouble with the if and else clauses here, can anybody help me troubleshoot this code? I have been going over it and to me it looks like it should be able to build, but visual studio doesn't like the if/else for some reason. Any help is greatly appreciated.

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

using namespace std;
void main ()

{ int acctno, code, dep=0, wit=0;
  float amount, balance, endbalance, deptot=0, wtot=0;
  
  ifstream fin;
  ofstream fout;
fin.open("Bank.dat");
fout.open("totals.dat");
fout.setf (ios::fixed);
fout.setf (ios::showpoint);
fout.precision (2);
  
 while (!fin.eof())
   	{if(code==1)
  	endbalance=amount+balance;
  	fout<<acctno<<endbalance<<"Have a nice day"<<endl;
  	deptot=amount+deptot;
  	dep++;  
  	fin>>acctno>>code>>amount>>balance;

	else
	{if (code==2)
 	   {if (amount>balance)
		fout<<acctno<<"insufficient funds"<<endl;
			
		else(amount<=balance);
		endbalance=balance-amount;
	   {if  (endbalance>=100.00)
	        fout<<acctno<<endbalance<<"Have a nice day"<<endl;
		wtot=amount+wtot;
		wit++;
	   else(endbalance<100.00)
		endbalance=endbalance-10.00;
		fout<<acctno<<"balance below $100.00 minimum -- $10.00 fee accessed"<<endbalance<<endl;
		wtot=amount+wtot;
		wit++;
	}
	}
	}
	else(code!=1)||(code!=2)
  		fout<<acctno<<"bad transaction code"<<endl;
	}
}
you're missing many braces, didn't used if - else if - else properly and misplaced some braces

remember that else doesn't have a condition beside them, use else-if instead
Last edited on
You need to put braces { } around the block of statements to be controlled by the if/else. Without them, only the very first statement after the if is dependent upon it.
Topic archived. No new replies allowed.