Sep 25, 2014 at 5:01pm UTC
//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
}
Sep 25, 2014 at 5:10pm UTC
just need to know what im doing wrong with connecting else statements to if statements
Sep 25, 2014 at 5:19pm UTC
Look for extra semicolons - you have a couple at the end of statements where they shouldn't be.
Sep 25, 2014 at 5:20pm UTC
sorry about that, i'm new here
Sep 25, 2014 at 5:25pm UTC
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
?
Sep 25, 2014 at 5:37pm UTC
all problems are on line 62
Sep 25, 2014 at 5:41pm UTC
The compiler can't match up the else on line 62 because you have extra semicolons further up the code.
Sep 25, 2014 at 5:57pm UTC
Problem solved. Can't believe I put a semicolon on a while loop....