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

	void DisplayTitle();
	void DisplayBal(double);
    void GetData(int& , double&);
	double ProcessCheck(double, double);
	double ProcessDeposit(double, double);
	double ProcessATM(double, double);
	double ProcessSvcChg(double);

    struct transrec
	{
		double credids;
		double debits;
		double service charges;
	};



const double	CHARGE = 10,
				ATMFEE =  2;

int main()
{
	
	int transCode;
	double balance,
		   transAmt;

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	DisplayTitle();
	GetData(transCode, transAmt);

	ifstream input;
    ofstream output;

	input.open("C:\\checkin.dat", ios::app);

if ( input.fail())
{
	cout<< " Input file failed to open\n";
	system("pause");
	exit(1);
}

output.open("C:\\checkout.txt",ios::app);
if ( output.fail())
{
	cout<< "output file opening failed\n";
	system("pause");
	exit(1);
}



transrec GetData (ifstream& file)
{
transRec temp;
file >> temp.code >> temp.amt;
return temp;
}
	while(transCode !=0 )
	{
		switch(transCode)
		{
			case 1: balance = ProcessCheck(balance, transAmt); break;
			case 2: balance = ProcessDeposit(balance, transAmt); break;
			case 3: balance = ProcessATM(balance, transAmt); break;
		}
		DisplayBal(balance);
		if(balance < 0)
			balance = ProcessSvcChg(balance);
		GetData(transCode, transAmt);
	}
	
return 0;
}	


	void DisplayTitle()
	{
		cout << "\n       Check Register\n\n";
	}

	

	void DisplayBal(double x)
	{
		cout << "\t\tBalance = $" << setw(10) << x;
	}

	void GetData(int& x, double& 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);
	}

problem is it i compile it with no error messages afterwards i get 14 when i try any ideas? any helpw ould be greatful

could you elaborate more on your problem

.\code.cpp(23) : error C2146: syntax error : missing ';' before identifier 'charges'
.\code.cpp(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\code.cpp(68) : error C2601: 'GetData' : local function definitions are illegal
.\code.cpp(32): this line contains a '{' which has not yet been matched
.\code.cpp(84) : error C2660: 'GetData' : function does not take 2 arguments
.\code.cpp(69) : error C2065: 'transRec' : undeclared identifier
.\code.cpp(69) : error C2146: syntax error : missing ';' before identifier 'temp'
.\code.cpp(69) : error C2065: 'temp' : undeclared identifier
.\code.cpp(70) : error C2228: left of '.code' must have class/struct/union
type is ''unknown-type''
.\code.cpp(70) : error C2228: left of '.amt' must have class/struct/union
type is ''unknown-type''
.\code.cpp(107) : error C2059: syntax error : '}'
.\code.cpp(107) : error C2143: syntax error : missing ';' before '}'
.\code.cpp(107) : error C2059: syntax error : '}'
.\code.cpp(110) : error C2143: syntax error : missing ';' before '{'
.\code.cpp(110) : error C2447: '{' : missing function header (old-style formal list?)
Build log was saved at "file://c:\Documents and Settings\YogiBoo\My Documents\Visual Studio 2005\Projects\pj8\pj8\Debug\BuildLog.htm"
pj8 - 14 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

this is everything that comes up after i try running it but i get no error messages when i compile it.

Edited 3 Years Ago by happygeek: fixed formatting

you should change line 23

const double CHARGE = 10;	
const double ATMFEE =  2;

your GetData function definition has got no variables referenced but you are calling it with variables..change lline 8

void GetData(int& transCode, double& , transAmt);

after line 43 add "}"

you need to read through the errors and try to solve them cuz most of your errors are syntax i.e your missing braces at the end of functions and your forgetting every statement should be ended with a ";"

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 <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
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);
}

Edited 3 Years Ago by Dani: Formatting fixed

your compiler settings may have been change to not recognize syntax errors or ignore warnings..so when you build your program it cannot go anywhere until the errors have been fixed....can you repost your code with code tags and be specific with your problem...

your compiler settings may have been change to not recognize syntax errors or ignore warnings..so when you build your program it cannot go anywhere until the errors have been fixed....can you repost your code with code tags and be specific with your problem...

olution.obj : error LNK2005: "void __cdecl DisplayBal(double)" (?DisplayBal@@YAXN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessCheck(double,double)" (?ProcessCheck@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessDeposit(double,double)" (?ProcessDeposit@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessATM(double,double)" (?ProcessATM@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessSvcChg(double)" (?ProcessSvcChg@@YANN@Z) already defined in code.obj
solution.obj : error LNK2005: _main already defined in code.obj
C:\Documents and Settings\YogiBoo\My Documents\Visual Studio 2005\Projects\pj8\Debug\pj8.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Documents and Settings\YogiBoo\My Documents\Visual Studio 2005\Projects\pj8\pj8\Debug\BuildLog.htm"

First thank you for taking your time to help me i appreciate it alot:)
I have coded things recently on it and it never tends to do that maybe it is not opening the file right? Because i know sometimes when you change something you can get like 50 syntax errors but it can be fixed by one thing. You think maybe that is the problem?

hi..can you please post the 'correct' version of code using code tags and also the errors in one single post. That ways it'll be easier for people who want to help.

hi..can you please post the 'correct' version of code using code tags [ICODE]and also the errors in one single post. That ways it'll be easier for people who want to help.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
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);
}

syntax errors:

solution.obj : error LNK2005: "void __cdecl DisplayBal(double)" (?DisplayBal@@YAXN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessCheck(double,double)" (?ProcessCheck@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessDeposit(double,double)" (?ProcessDeposit@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessATM(double,double)" (?ProcessATM@@YANNN@Z) already defined in code.obj
solution.obj : error LNK2005: "double __cdecl ProcessSvcChg(double)" (?ProcessSvcChg@@YANN@Z) already defined in code.obj
solution.obj : error LNK2005: _main already defined in code.obj
C:\Documents and Settings\YogiBoo\My Documents\Visual Studio 2005\Projects\pj8\Debug\pj8.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Documents and Settings\YogiBoo\My Documents\Visual Studio 2005\Projects\pj8\pj8\Debug\BuildLog.htm"

Edited 3 Years Ago by Dani: Formatting fixed

am finding it hard to read ur code..can u re post it using code tags

what are code tags?

look at the edit features where you create you post

k i did it to my last post hope i did it right.

i think you need to put header guards in your header file

#ifndef /*your header file name*/_H_INCLUDED
#define /*your header file name*/_H_INCLUDED
//what is contained in the header file

#endif

it compiles well on my visual studio 6 but it looks like you are using visual studio express...can you create a project file and make sure there are no duplicate files there

can you try creating that same file name and plugging in these numbers into it

2000 1 1225.72 1 463.81 3 200 4 632 2 1500 1 300 2 1800

and see if it will run... I created the project file I should only have checkinfile in there right?
thank you

i dont know what the program is suposed to do but the output looks okay..can u try doing what i indicated in my last post

i dont know what the program is suposed to do but the output looks okay..can u try doing what i indicated in my last post

it is supposed to read from a file which include the numbers i gave you and plug them into the program. I saw what you posted and am not sure what you mean by it because i thought i did can you give me an example of what you mean with one line of code from my code?

if your header file is called header1.h then you can do this

#ifndef header1_H_INCLUDED
#define header1_H_INCLUDED

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

void DisplayTitle();
double GetBegBal(ifstream& f);

.
.
.
#endif

if your header file is called header1.h then you can do this

#ifndef header1_H_INCLUDED
#define header1_H_INCLUDED

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

void DisplayTitle();
double GetBegBal(ifstream& f);

.
.
.
#endif

yes that worked you are a god i have never even seen that code before thank you. It says input file has failed to open but i can fix that thank you:)

This question has already been answered. Start a new discussion instead.