help fix Compiling error

bank account program need to fix error

Page 1 of 1

7 Replies - 3402 Views - Last Post: 02 December 2006 - 07:27 AM Rate Topic: -----

#1 rantwi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 06

help fix Compiling error

Posted 01 December 2006 - 09:53 PM

I am working on program and I need to fix some small errors, you don't need to fix the program because it is not done yet, but if you can help me fix the compiling error, especially the first error that will help.

main //not much is done ,just check for file open and close
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

#include "account.h"
#include "savings.h"

int Account::NDM =0;
int Account::NW =0;
int main()
{
	ifstream infile;
	char filename[14];
	
	cout <<"Enter the filename: ";
	cin >>filename;

	fileOpen(filename, infile);
	fileClose(infile);

 return 0;
}
	void fileOpen(char filename[14], ifstream& infile)
	{
		infile.open(filename);
	if (infile.fail())
	{
		cerr << "\a\nERROR 1: File could not be opened."<<endl;
		exit(1);
	}
	else
	{
		cout << "\nThe external file has been successfully opened for writing."<<endl;
	}
		return;
	}	

	void fileClose(ifstream& infile)
	{
		infile.close();
	if (infile.fail())
		{
		cerr << "\a\nERROR 2: File could not be closed."<< endl;
		exit(2);
		}
	else
		{
		cout <<"\nThe external file has been successfully closed."<<endl;
		}
		return;
	}


Account.h
class Account
{

	protected:
static  int NDM,NW;
		double MIR,MI,bal,MonScharge;
		float Ai,money;
	public:
		Account(int);
		void deposit(int);
		void withdraw(int);
		void calclnt();
		void MonthlyProc();
};

Account::Account(int mon):bal(0.0),Ai(0.0)
{
	money = mon;
	NDM++;
	NW++;
}

void Account::deposit(int mon)
{
	money = mon;
	bal = bal+money;
	return;
}

void Account::withdraw(int mon)
{
	money = mon;
	bal = bal-money;
	return;
}
void Account::calclnt()
{
	MIR = Ai/12;
	MI = bal*MIR;
	bal = bal+MI;
	return;
}

void Account::MonthlyProc()
{
	bal = bal-MonScharge;
	calclnt();
	NW=0;
	NDM=0;
	MonScharge=0;
	return;
}


Savings.h
class Savings:protected Account
{
public:
void	withdraw();
void	deposit(int);
void	MonthlyProc();
};

void Savings::withdraw()
{
	{
	if (bal >= 25)
		Account::withdraw(int)
		NW++;
	}

		else
	{
		cerr <<"\nSorry balance is below $25 *Can't withdraw*"<<endl;
	}
	return;
}

void Savings::deposit(int)
{
	money = mon;
	if(bal+money >= 25.0)
	{
		Account::deposit(int);
		NDM++;
	}
	else
	{
		cout <<"\nSorry the money your depositing will not make the account active."<<endl;
	}
	return;
}

void Savings::MonthlyProc()
{
	if(NW >4)
	{
	MonScharge=1;
	Account::MonthlyProc();
	}
	else
	{
		Account::MonthlyProc();
	}
	if(bal =>25)
	{
		cout <<"\nAccount is Active."<<endl;
	}
	else
	{
		cout <<"\nAccount is Inactive."<<endl;
	}
	return;
}


Is This A Good Question/Topic? 0
  • +

Replies To: help fix Compiling error

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: help fix Compiling error

Posted 01 December 2006 - 10:26 PM

Post the error messages that you are getting.
Was This Post Helpful? 0
  • +
  • -

#3 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: help fix Compiling error

Posted 02 December 2006 - 01:15 AM

fixed a few errors in Accounts.h - in particular you need a default constructor if you have a constructor with parameters and there were two versions of void Account::deposit(int mon)
class Account
{

	protected:
static  int NDM,NW;
		double MIR,MI,bal,MonScharge;
		float Ai,money;
	public:
		Account();  // ** added
		Account(int);
		void deposit(int);
		void withdraw(int);
		void calclnt();
		void MonthlyProc();
};

Account::Account():bal(0.0),Ai(0.0)   // ** you need a default constructor
{
	money = 0;   
	NDM++;
	NW++;
}

void Account::deposit(int mon)
{
	money = mon;
	bal = bal+money;
	return;
}

/*void Account::deposit(int mon)	// ** second version of Account
{
	money = mon;
	bal = bal+money;
	return;
}*/

void Account::withdraw(int mon)
{
	money = mon;
	bal = bal-money;
	return;
}
void Account::calclnt()
{
	MIR = Ai/12;
	MI = bal*MIR;
	bal = bal+MI;
	return;
}

void Account::MonthlyProc()
{
	bal = bal-MonScharge;
	calclnt();
	NW=0;
	NDM=0;
	MonScharge=0;
	return;
}



now have a go at fixing other errors, e.g. in Saving::withdraw() what should be the parameter to
		Account::withdraw(int)


This post has been edited by horace: 02 December 2006 - 05:00 AM

Was This Post Helpful? 0
  • +
  • -

#4 rantwi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 06

Re: help fix Compiling error

Posted 02 December 2006 - 05:36 AM

I have managed to fix some, but the first one from before will not "bug" away.

--------------------Configuration: base account - Win32 Debug--------------------
Compiling...
main.cpp
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2660: 'withdraw' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2059: syntax error : ')'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2660: 'deposit' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2059: syntax error : ')'
Error executing cl.exe.

base account.exe - 6 error(s), 0 warning(s) 

Was This Post Helpful? 0
  • +
  • -

#5 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: help fix Compiling error

Posted 02 December 2006 - 06:06 AM

View Postrantwi, on 2 Dec, 2006 - 12:36 PM, said:

I have managed to fix some, but the first one from before will not "bug" away.

--------------------Configuration: base account - Win32 Debug--------------------
Compiling...
main.cpp
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2660: 'withdraw' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(14) : error C2059: syntax error : ')'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2660: 'deposit' : function does not take 0 parameters
c:\documents and settings\administrator\desktop\final project\base account\savings.h(30) : error C2059: syntax error : ')'
Error executing cl.exe.

base account.exe - 6 error(s), 0 warning(s) 

the probelems are in lines 13 and 29, i.e.
		Account::withdraw(int)


line 13 has a ; missing off the end and both have the parameter int which is a C++ keyword using to declare integer variables.

have a look at
http://www.cplusplus.../functions.html
on how function parameters are declared and passed
Was This Post Helpful? 0
  • +
  • -

#6 rantwi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 06

Re: help fix Compiling error

Posted 02 December 2006 - 06:42 AM

WOW! zero errors, and all I had to do is insted of Account::withdraw(int); it would be:

void Account::withdraw(int);




Thanx horace :)
Was This Post Helpful? 0
  • +
  • -

#7 rantwi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-December 06

Re: help fix Compiling error

Posted 02 December 2006 - 07:14 AM

I have another question if you don't mind
I want to open a file like this:

Account Type Traction Type Amount

S w 1000
S 0 234
S d 34
c e 200
S e 2000



I want to be able to link s=savings, then w=withdraw, and then either deposit or withdraw(depending on the traction type, o-open and d=deposit)

of course I have started the program as you can see from above, but I am not looking the answer, but if you can direct me to a link that I can learn this that will be helpful

PS, I know how to assign data types to work for specific type (like string for s,w,o and int or double for 1000,234..)
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: help fix Compiling error

Posted 02 December 2006 - 07:27 AM

File I/O

http://www.cplusplus...rial/files.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1