need help with program

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

need help with program

 
0
  #1
May 9th, 2008
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. void DisplayTitle();
  7. void DisplayBal(double);
  8. void GetData(int& , double&);
  9. double ProcessCheck(double, double);
  10. double ProcessDeposit(double, double);
  11. double ProcessATM(double, double);
  12. double ProcessSvcChg(double);
  13.  
  14. struct transrec
  15. {
  16. double credids;
  17. double debits;
  18. double service charges;
  19. };
  20.  
  21.  
  22.  
  23. const double CHARGE = 10,
  24. ATMFEE = 2;
  25.  
  26. int main()
  27. {
  28.  
  29. int transCode;
  30. double balance,
  31. transAmt;
  32.  
  33. cout.setf(ios::fixed);
  34. cout.setf(ios::showpoint);
  35. cout.precision(2);
  36.  
  37. DisplayTitle();
  38. GetData(transCode, transAmt);
  39.  
  40. ifstream input;
  41. ofstream output;
  42.  
  43. input.open("C:\\checkin.dat", ios::app);
  44.  
  45. if ( input.fail())
  46. {
  47. cout<< " Input file failed to open\n";
  48. system("pause");
  49. exit(1);
  50. }
  51.  
  52. output.open("C:\\checkout.txt",ios::app);
  53. if ( output.fail())
  54. {
  55. cout<< "output file opening failed\n";
  56. system("pause");
  57. exit(1);
  58. }
  59.  
  60.  
  61.  
  62. transrec GetData (ifstream& file)
  63. {
  64. transRec temp;
  65. file >> temp.code >> temp.amt;
  66. return temp;
  67. }
  68. while(transCode !=0 )
  69. {
  70. switch(transCode)
  71. {
  72. case 1: balance = ProcessCheck(balance, transAmt); break;
  73. case 2: balance = ProcessDeposit(balance, transAmt); break;
  74. case 3: balance = ProcessATM(balance, transAmt); break;
  75. }
  76. DisplayBal(balance);
  77. if(balance < 0)
  78. balance = ProcessSvcChg(balance);
  79. GetData(transCode, transAmt);
  80. }
  81.  
  82. return 0;
  83. }
  84.  
  85.  
  86. void DisplayTitle()
  87. {
  88. cout << "\n Check Register\n\n";
  89. }
  90.  
  91.  
  92.  
  93. void DisplayBal(double x)
  94. {
  95. cout << "\t\tBalance = $" << setw(10) << x;
  96. }
  97.  
  98. void GetData(int& x, double& y)
  99. {
  100.  
  101. }
  102. }
  103.  
  104. double ProcessCheck(double bal, double amt)
  105. {
  106. cout << "\n Check = " << setw(10) << amt;
  107. return (bal - amt);
  108. }
  109.  
  110. double ProcessDeposit(double bal, double amt)
  111. {
  112. cout << "\n Deposit = " << setw(10) << amt;
  113. return (bal + amt);
  114. }
  115. double ProcessATM(double bal, double amt)
  116. {
  117. cout << "\n ATM = " << setw(10) << amt;
  118. bal = bal - amt;
  119. DisplayBal(bal);
  120. bal = bal - ATMFEE;
  121. cout << "\n ATM Fee = " << setw(10) << ATMFEE;
  122. return (bal);
  123. }
  124. double ProcessSvcChg(double bal)
  125. {
  126. cout << "\n Service chg =" << setw(8) << CHARGE;
  127. bal = bal - CHARGE;
  128. DisplayBal(bal);
  129. return (bal);
  130. }
problem is it i compile it with no error messages afterwards i get 14 when i try any ideas? any helpw ould be greatful
Last edited by Ancient Dragon; May 9th, 2008 at 1:50 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: need help with program

 
0
  #2
May 9th, 2008
could you elaborate more on your problem
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

Re: need help with program

 
0
  #3
May 9th, 2008
Originally Posted by joshmo View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: need help with program

 
0
  #4
May 9th, 2008
you should change line 23
  1. const double CHARGE = 10;
  2. const double ATMFEE = 2;

your GetData function definition has got no variables referenced but you are calling it with variables..change lline 8
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

Re: need help with program

 
0
  #5
May 9th, 2008
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);
}
Last edited by blackhawk9876; May 9th, 2008 at 3:00 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: need help with program

 
0
  #6
May 9th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

Re: need help with program

 
0
  #7
May 9th, 2008
Originally Posted by joshmo View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 449
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 70
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: need help with program

 
0
  #8
May 9th, 2008
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.
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 14
Reputation: blackhawk9876 is an unknown quantity at this point 
Solved Threads: 0
blackhawk9876 blackhawk9876 is offline Offline
Newbie Poster

Re: need help with program

 
0
  #9
May 9th, 2008
Originally Posted by Agni View Post
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;
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; };

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: need help with program

 
0
  #10
May 9th, 2008
am finding it hard to read ur code..can u re post it using code tags
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC