| | |
need help with program
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#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); }
Last edited by Ancient Dragon; May 9th, 2008 at 1:50 am. Reason: add code tags
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
.\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.
.\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.
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
you should change line 23
your GetData function definition has got no variables referenced but you are calling it with variables..change lline 8
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 ";"
C++ Syntax (Toggle Plain Text)
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
C++ Syntax (Toggle Plain Text)
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 ";"
Last edited by joshmo; May 9th, 2008 at 2:45 am.
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
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);
}
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);
}
Last edited by blackhawk9876; May 9th, 2008 at 3:00 am.
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
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...
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?
•
•
Join Date: May 2008
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
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. #include <iostream> #include <iomanip> #include <fstream> #include <cstdlib> using namespace std;struct transrecord { int transCode; double transAmt; }; struct totals { int credits; int debits; int service; };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);
c
onst 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"
Last edited by blackhawk9876; May 9th, 2008 at 4:24 am.
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: function problem
- Next Thread: film gate
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy directshow dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings studio temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





