Errors that I am receving

Transactioncounter is undeclared
class SavingsAccount has no member name transactionCounter
class SavingsAccount has no member name getTotalLostToFee
class SavingsAccount has no member name transactionCounter
class CheckingAccount has no member name getTotalLostToFee
unterminated #ifndef
amount undeclared

#include <fstream>
#include "COSC214Lab3.h"

using namespace std;



int main()
{
    
    SavingsAccount savingsAccount;
    savingsAccount.getBalance();
    savingsAccount.setBalance(amount);
    savingsAccount.withdraw(amount);
    savingsAccount.deposit(amount);
    savingsAccount.getTotalLostToFee();
    savingsAccount.getTransactionCounter();
    
    CheckingAccount checkingAccount;
    checkingAccount.getBalance();
    checkingAccount.setBalance(amount);
    checkingAccount.withdraw(amount);
    checkingAccount.deposit(amount);
    checkingAccount.getTotalLostToFee();
    checkingAccount.getTransactionCounter();

ifstream inData("input.txt");
ofstream outData("output.txt");

string transactionType, accountType;	
double amount;

while(inData >> accountType >> transactionType >>  amount)
{
	if(accountType == "savings")
	{
		if(transactionType == "deposit")
		{
			savingsAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			savingsAccount.withdraw(amount);
		}
	}
	else if(accountType == "checking")
	{
		if(transactionType == "deposit")
		{
			checkingAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			checkingAccount.withdraw(amount);
		}
	}
}

outData << "Savings Total: " << savingsAccount.getBalance() << endl;
outData << "Checking Total: " << checkingAccount.getBalance() << endl;
    
    
system ("PAUSE");
return 0;
}
#ifndef COSC214Lab3_H
#define COSC214Lab3_H

class SavingsAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.0;
      double transactioncounter;
      double totalLostToFee;
      
	public:
		SavingsAccount();
		SavingsAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		getTotalLostToFee();
		getTransactionCounter();

};



class CheckingAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.5;
      double transactioncounter;
      double totalLostToFee;
      
public:
      	CheckingAccount();
		CheckingAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		getTotalLostToFee();
		getTransactionCounter();

};


SavingsAccount::SavingsAccount()
{	
    
    balance = 100.0;

} 

SavingsAccount::SavingsAccount(double balance)
{	
    balance = balance;
    
}

void SavingsAccount::setBalance(double amount)
{
    
    balance = amount; 
     
}


void SavingsAccount::withdraw(double amount)
{
   balance -= amount + WITHDRAW_FEE;  
   totalLostToFee += amount*WITHDRAW_FEE;
   transactionCounter++;
}


void SavingsAccount::deposit(double amount)
{
     balance += amount;
     transactionCounter++;
     
}

double SavingsAccount::getBalance()
{
       
 return balance;      
       
}



CheckingAccount::CheckingAccount()
{	
    
    balance = 100.0;

} 

CheckingAccount::CheckingAccount(double balance)
{	
    balance = balance;
    
}

void CheckingAccount::setBalance(double amount)
{
     
     balance = amount;
     
}



void CheckingAccount::withdraw(double amount)
{
     
    balance -= amount + WITHDRAW_FEE; 
    totalLostToFee += amount*WITHDRAW_FEE;
    transactionCounter++;
}


void CheckingAccount::deposit(double amount)
{
     
     balance += amount;
     transactionCounter++;
     
}

double CheckingAccount::getBalance()
{
       
  return balance;   
       
}


#endif

After looking over this I see you are calling the functions at the start of main() and I have no clue why.

All you have to do is declare them

SavingsAccount savingsAccount;
CheckingAccount checkingAccount;

Do not do their functions and use amount as a parameter when it has not been defined yet.

Also one thing to remember is that variables are case sensitive so transactioncounter is not the same as transactionCounter so pick one and use it.

In the class constructors you need to assign transactionCounter and totalLostToFee a value (zero or something) or try declaring them as static doubles (not constant because you want their value to change).

I see you just put getTransactionCounter() without a return type. You want:

double getTransactionCounter()

do the same for the Fee variable too.

It looks like the #ifndef statement closer is fixed with the #endif but let me know if that is still an error.

so delete amount in the parameters of all of them inside of main?

Can you give another example incase i do something wrong

Notice how I am just making savingsAccount and checkingAccount and not trying to run the functions? This is exactly what you want to have for your main.cpp file.

"main.cpp"

#include <fstream>
#include "account.h"

using namespace std;

int main()
{
	SavingsAccount savingsAccount;
	CheckingAccount checkingAccount;
	
	ifstream inData("input.txt");
	ofstream outData("output.txt");
	
	string transactionType, accountType;
	double amount;
	
	while(inData >> accountType >> transactionType >> amount )
	{
		if( accountType == "savings" )
		{
			
			if( transactionType == "deposit" )
			{
				savingsAccount.deposit(amount);
				
			}
			else if( transactionType == "withdraw" )
			{
				savingsAccount.withdraw(amount);
			}
		}
		else if( accountType == "checking" )
		{
			if( transactionType == "deposit" )
			{
				checkingAccount.deposit(amount);
			}
			else if( transactionType == "withdraw" )
			{
				checkingAccount.withdraw(amount);
			}
		}
	}
	
	outData << "Savings Total: " << savingsAccount.getBalance() << endl;
	outData << "Checking Total: " << checkingAccount.getBalance() << endl;
	
	system("PAUSE");
	return 0;
};

seems like a lot of errors cleared however, it is still showing that transactionCounter and totalLostToFee is undeclared

#include <fstream>
#include "COSC214Lab3.h"

using namespace std;



int main()
{
    
    SavingsAccount savingsAccount;
    CheckingAccount checkingAccount;


ifstream inData("input.txt");
ofstream outData("output.txt");

string transactionType, accountType;	
double amount;

while(inData >> accountType >> transactionType >>  amount)
{
	if(accountType == "savings")
	{
		if(transactionType == "deposit")
		{
			savingsAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			savingsAccount.withdraw(amount);
		}
	}
	else if(accountType == "checking")
	{
		if(transactionType == "deposit")
		{
			checkingAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			checkingAccount.withdraw(amount);
		}
	}
}

outData << "Savings Total: " << savingsAccount.getBalance() << endl;
outData << "Checking Total: " << checkingAccount.getBalance() << endl;
    
    
system ("PAUSE");
return 0;
}
//#ifndef COSC214Lab3_H
#define COSC214Lab3_H

class SavingsAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.0;
      double transactionCounter = 0;
      double totalLostToFee = 0;
      
	public:
		SavingsAccount();
		SavingsAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};



class CheckingAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.5;
      double transactionCounter = 0;
      double totalLostToFee = 0;
      
public:
      	CheckingAccount();
		CheckingAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};


SavingsAccount::SavingsAccount()
{	
    
    balance = 100.0;

} 

SavingsAccount::SavingsAccount(double balance)
{	
    balance = balance;
    
}

void SavingsAccount::setBalance(double amount)
{
    
    balance = amount; 
     
}


void SavingsAccount::withdraw(double amount)
{
   balance -= amount + WITHDRAW_FEE;  
   totalLostToFee += amount*WITHDRAW_FEE;
   transactionCounter++;
}


void SavingsAccount::deposit(double amount)
{
     balance += amount;
     transactionCounter++;
     
}

double SavingsAccount::getBalance()
{
       
 return balance;      
       
}


double SavingsAccount::getTotalLostToFee()
{
       
       
       
}

double SavingsAccount::getTransactionCounter()
{
       
       
       
}


CheckingAccount::CheckingAccount()
{	
    
    balance = 100.0;

} 

CheckingAccount::CheckingAccount(double balance)
{	
    balance = balance;
    
}

void CheckingAccount::setBalance(double amount)
{
     
     balance = amount;
     
}



void CheckingAccount::withdraw(double amount)
{
     
    balance -= amount + WITHDRAW_FEE; 
    totalLostToFee += amount*WITHDRAW_FEE;
    transactionCounter++;
}


void CheckingAccount::deposit(double amount)
{
     
     balance += amount;
     transactionCounter++;
     
}

double CheckingAccount::getBalance()
{
       
  return balance;   
       
}

double CheckingAccount::getTotalLostToFee()
{
       
       
       
}

double CheckingAccount::getTransactionCounter()
{
       
       
       
}

//#endif

also for the new functions getTransactionCounter and getTotalLostToFee, I am using "return transactionCounter++" in getTransactionCounter and "return totalLostToFee" in getTotalLostToFee?

Yeah but the ++ at the end just means increase by 1 so that is not part of the variable name.

Also try going

static double totalLostToFee = 0;
static double transactionCounter = 0;

it is still saying it is undeclared for both variables locating it on

Lines

Line 62 transactionCounter (points inside void SavingsAccount::setBalance(double amount) )

Line 69 transactionCounter (points inside void SavingsAccount::withdraw(double amount) )

Line 108 totalLostToFee (points inside CheckingAccount::CheckingAccount() )

Line 109 transactionCounter (points inside CheckingAccount::CheckingAccount() )

Line 117 - transactionCounter (points inside void CheckingAccount::setBalance(double amount) )

It's really hard to tell what is wrong when I can't see what you changed but if it is saying that it is undeclared then that means you misspelled the variable name or you didn't declare it in the class properly.

Here is the updated code:


Also, where do I print out the transactionCounter and totalLostToFee?

#include <fstream>
#include "COSC214Lab3.h"

using namespace std;



int main()
{
    
    SavingsAccount savingsAccount;
    CheckingAccount checkingAccount;


ifstream inData("input.txt");
ofstream outData("output.txt");

string transactionType, accountType;	
double amount;

while(inData >> accountType >> transactionType >>  amount)
{
	if(accountType == "savings")
	{
		if(transactionType == "deposit")
		{
			savingsAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			savingsAccount.withdraw(amount);
		}
	}
	else if(accountType == "checking")
	{
		if(transactionType == "deposit")
		{
			checkingAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			checkingAccount.withdraw(amount);
		}
	}
}

outData << "Savings Total: " << savingsAccount.getBalance() << endl;
outData << "Checking Total: " << checkingAccount.getBalance() << endl;
    
    
system ("PAUSE");
return 0;
}
#ifndef COSC214Lab3_H
#define COSC214Lab3_H

class SavingsAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.0;
      static double totalLostToFee = 0;
      static double transactionCounter = 0;
      
	public:
		SavingsAccount();
		SavingsAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};



class CheckingAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.5;
      static double totalLostToFee = 0;
      static double transactionCounter = 0;
      
public:
      	CheckingAccount();
		CheckingAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};


SavingsAccount::SavingsAccount()
{	
    
    balance = 100.0;

} 

SavingsAccount::SavingsAccount(double balance)
{	
    balance = balance;
    
}

void SavingsAccount::setBalance(double amount)
{
    
    balance = amount; 
     
}


void SavingsAccount::withdraw(double amount)
{
   balance -= amount + WITHDRAW_FEE;  
   totalLostToFee += amount*WITHDRAW_FEE;
   transactionCounter++;
}


void SavingsAccount::deposit(double amount)
{
     balance += amount;
     transactionCounter++;
     
}

double SavingsAccount::getBalance()
{
       
 return balance;      
       
}


double SavingsAccount::getTotalLostToFee()
{
       
   return totalLostToFee;    
       
}

double SavingsAccount::getTransactionCounter()
{
       
   return transactionCounter;    
       
}


CheckingAccount::CheckingAccount()
{	
    
    balance = 100.0;

} 

CheckingAccount::CheckingAccount(double balance)
{	
    balance = balance;
    
}

void CheckingAccount::setBalance(double amount)
{
     
     balance = amount;
     
}



void CheckingAccount::withdraw(double amount)
{
     
    balance -= amount + WITHDRAW_FEE; 
    totalLostToFee += amount*WITHDRAW_FEE;
    transactionCounter++;
}


void CheckingAccount::deposit(double amount)
{
     
     balance += amount;
     transactionCounter++;
     
}

double CheckingAccount::getBalance()
{
       
  return balance;   
       
}

double CheckingAccount::getTotalLostToFee()
{
       
   return totalLostToFee;    
       
}

double CheckingAccount::getTransactionCounter()
{
       
   return transactionCounter;    
       
}

#endif

That looks error free to me tell me if you still have some in that class tho.

As for outputting the counter and fees you put that right under the other 2 outputs

outData << "Savings Total: " << savingsAccount.getBalance() << endl;
outData << "Savings Total Transactions: " << savingsAccount.getTransactionCounter() << endl;
outData << "Savings Total Lost to Withdraw Fee: " << savingsAccount.getTotalLostToFee() << endl;
outData << "Checking Total: " << checkingAccount.getBalance() << endl;
outData << "Checking Total Transactions: " << checkingAccount.getTransactionCounter() << endl;
outData << "Checking Total Lost to Withdraw Fee: " << checkingAccount.getTotalLostToFee() << endl;

it seems like the transactionCounter and totalLostToFee are having problems in

void SavingsAccount::withdraw(double amount)

OK my fault here I was just talking and not testing.

You need to change

static double counter= 0;
static double loss= 0;

to

double counter;
double loss;

I made up variable names here because I'm getting tired =(.
Now go into the constructors and assign zero to these.

SavingsAccount::SavingsAccount()
{
	balance = 100.0;
	counter = 0;
	loss = 0;
}

SavingsAccount::SavingsAccount( double balance )
{
	balance = balance;
	counter = 0;
	loss = 0;
}

This way when you go counter++ you are not adding 1 to a undefined variable and that would give you some random number.
This fix should work. Get back to me fast if you have any questions because I plan on calling it a night in 30 min or so.

It didn't work...It still gave the same undeclared error.


For the outData stuff that we did, it says the class has no member name

outData << "Savings Total Transactions: " << savingsAccount.getTransactionCounter() << endl;
outData << "Savings Total Lost to Withdraw Fee: " << savingsAccount.getTotalLostToFee() << endl;
outData << "Checking Total Transactions: " << checkingAccount.getTransactionCounter() << endl;
outData << "Checking Total Lost to Withdraw Fee: " << checkingAccount.getTotalLostToFee() << endl;

I guess we should give up. My deadline is a few hours and I haven't had sleep for 2 days.

#include <fstream>
#include "COSC214Lab3.h"

using namespace std;



int main()
{
    
    SavingsAccount savingsAccount;
    CheckingAccount checkingAccount;


ifstream inData("input.txt");
ofstream outData("output.txt");

string transactionType, accountType;	
double amount;

while(inData >> accountType >> transactionType >>  amount)
{
	if(accountType == "savings")
	{
		if(transactionType == "deposit")
		{
			savingsAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			savingsAccount.withdraw(amount);
		}
	}
	else if(accountType == "checking")
	{
		if(transactionType == "deposit")
		{
			checkingAccount.deposit(amount);
		}
		else if(transactionType == "withdraw")
		{
			checkingAccount.withdraw(amount);
		}
	}
}

outData << "Savings Total: " << savingsAccount.getBalance() << endl;
outData << "Savings Total Transactions: " << savingsAccount.getTransactionCounter() << endl;
outData << "Savings Total Lost to Withdraw Fee: " << savingsAccount.getTotalLostToFee() << endl;
outData << "Checking Total: " << checkingAccount.getBalance() << endl;
outData << "Checking Total Transactions: " << checkingAccount.getTransactionCounter() << endl;
outData << "Checking Total Lost to Withdraw Fee: " << checkingAccount.getTotalLostToFee() << endl;
    
    
system ("PAUSE");
return 0;
}
#ifndef COSC214Lab3_H
#define COSC214Lab3_H

class SavingsAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.0;
      double totalLostToFee;
      double transactionCounter;
      
	public:
		SavingsAccount();
		SavingsAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};



class CheckingAccount
{
      double balance;
      static const double WITHDRAW_FEE = 0.5;
      double totalLostToFee;
      double transactionCounter;
      
public:
      	CheckingAccount();
		CheckingAccount(double balance);
		void setBalance(double amount);
		void withdraw(double amount);
		void deposit(double amount);
		double getBalance();
		double getTotalLostToFee();
		double getTransactionCounter();

};


SavingsAccount::SavingsAccount()
{	
    
    balance = 100.0;
    transactionCounter = 0;
    totalLostToFee = 0;

} 

SavingsAccount::SavingsAccount(double balance)
{	
    balance = balance;
    transactionCounter = 0;
    totalLostToFee = 0;
    
}

void SavingsAccount::setBalance(double amount)
{
    
    balance = amount; 
     
}


void SavingsAccount::withdraw(double amount)
{
   balance -= amount + WITHDRAW_FEE;  
   totalLostToFee += amount*WITHDRAW_FEE;
   transactionCounter++;
}


void SavingsAccount::deposit(double amount)
{
     balance += amount;
     transactionCounter++;
     
}

double SavingsAccount::getBalance()
{
       
 return balance;      
       
}


double SavingsAccount::getTotalLostToFee()
{
       
   return totalLostToFee;    
       
}

double SavingsAccount::getTransactionCounter()
{
       
   return transactionCounter;    
       
}


CheckingAccount::CheckingAccount()
{	
    
    balance = 100.0;
    transactionCounter = 0;
    totalLostToFee = 0;;

} 

CheckingAccount::CheckingAccount(double balance)
{	
    balance = balance;
    transactionCounter = 0;
    totalLostToFee = 0;;
    
}

void CheckingAccount::setBalance(double amount)
{
     
     balance = amount;
     
}



void CheckingAccount::withdraw(double amount)
{
     
    balance -= amount + WITHDRAW_FEE; 
    totalLostToFee += amount*WITHDRAW_FEE;
    transactionCounter++;
}


void CheckingAccount::deposit(double amount)
{
     
     balance += amount;
     transactionCounter++;
     
}

double CheckingAccount::getBalance()
{
       
  return balance;   
       
}

double CheckingAccount::getTotalLostToFee()
{
       
   return totalLostToFee;    
       
}

double CheckingAccount::getTransactionCounter()
{
       
   return transactionCounter;    
       
}

#endif

Why don't you just remove the counter and the loss thing and then submit it? It was working fine till we added that.

If you have any questions on other assignments feel free to PM me I find this stuff fun to work out.

I'm off to bed good night.

I got it to work. I had to close the program and start it back up for the changes to be made lol. We spent several hours on this and that is all I had to do. Thank you VERY much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.