my question is how come when i compile it, it is ok but not when i truy to run it?
im sorry i posted the wrong code
#include
#include
#include
#include
using namespace std;
void DisplayTitle();
double GetBegBal(ifstream& f);
void DisplayBal(double);
void GetData(int& x, double& y,ifstream&);
double ProcessCheck(double, double);
double ProcessDeposit(double, double);
double ProcessATM(double, double);
double ProcessSvcChg(double);
struct transrecord
{
int transCode;
double transAmt;
};
struct totals
{
int credits;
int debits;
int service;
};
const double CHARGE = 10,
ATMFEE = 2;
int main()
{
int transCode;
double balance,transAmt;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
ifstream infile;
ofstream outfile;
infile.open("checkin.dat",ios::in);
if (infile.fail())
{
cout<< "Input file opening failed.\n";
exit(1);
}
outfile.open("c:\\checkout.dat", ios::out);
if (outfile.fail())
{
cout<< "Output file opening failed.\n";
exit(1);
}
transrecord record;
record.transCode = 0;
DisplayTitle();
balance = GetBegBal(infile);
GetData(record.transCode, record.transAmt,infile);
while(record.transCode != 0)
{
switch(record.transCode)
{
case 1: balance = ProcessCheck(balance, record.transAmt); break;
case 2: balance = ProcessDeposit(balance, record.transAmt); break;
case 3: balance = ProcessATM(balance, record.transAmt); break;
}
DisplayBal(balance);
if(balance < 0)
balance = ProcessSvcChg(balance);
record.transCode = 0;
GetData(record.transCode, record.transAmt,infile);
}
/*while(!infile.eof())
{
record = GetData(infile);
}
*/
infile.close();
outfile.close();
return 0;
}
void DisplayTitle()
{
cout << "\n Check Register\n\n";
}
double GetBegBal(ifstream& f)
{
double x;
f>> x;
return x;
}
void DisplayBal(double x)
{
cout << "\t\tBalance = $" << setw(10) << x;
}
void GetData(int& x, double& y,ifstream& infile)
{
infile>>x;
infile>>y;
}
double ProcessCheck(double bal, double amt)
{
cout << "\n Check = " << setw(10) << amt;
return (bal - amt);
}
double ProcessDeposit(double bal, double amt)
{
cout << "\n Deposit = " << setw(10) << amt;
return (bal + amt);
}
double ProcessATM(double bal, double amt)
{
cout << "\n ATM = " << setw(10) << amt;
bal = bal - amt;
DisplayBal(bal);
bal = bal - ATMFEE;
cout << "\n ATM Fee = " << setw(10) << ATMFEE;
return (bal);
}
double ProcessSvcChg(double bal)
{
cout << "\n Service chg =" << setw(8) << CHARGE;
bal = bal - CHARGE;
DisplayBal(bal);
return (bal);
}