I am writing a Savings account program using a class with methods but it won't compile. I can't seem to figure out why.

Hhere is my program. It contains an header file, source code file, and a program cpp file:

Here is part of the error I get,

C:\Users\JEFF~1.JEF\AppData\Local\Temp\ccWScaaa.o(.text+0x17a) In function main': [Linker error] undefined reference toSavingsAccount::SavingsAccount(double)'
......

any help or pointers would be appreciated.

--------------------------
(Header File):

//Header file
#ifndef FILENAME_H
#define FILENAME_H

class SavingsAccount 
{

public:
SavingsAccount(double a);
~SavingsAccount();
static double modifyInterestRate(double b);
double calculateMonthlyInterest();
void printBalance();

private:

static double annInterestRate;
double saBalance;

};

#endif
//end 

(SavingsAccount .ccp):



#include <iostream>
#include "SavingsAccount.h"
using namespace std;


SavingsAccount::SavingsAccount(double a)
{
saBalance = a;        
annInterestRate = 0;
} 

SavingsAccount::~SavingsAccount()
{                                                           
}

double SavingsAccount::modifyInterestRate(double b)
{
   annInterestRate = b;    
}

double SavingsAccount::calculateMonthlyInterest()
{
  double interest = saBalance * annInterestRate;
  saBalance = saBalance + interest;    
}


void SavingsAccount::printBalance()
{
cout << saBalance << endl;   
}


double SavingsAccount::annInterestRate;


//end of Class Definition


(Program Driver cpp)


using namespace std;

#include <iostream> 
#include <iomanip> 
#include "SavingsAccount.h"

// Driver program below


int main()
{
   SavingsAccount saver1( 2000.0 );
   SavingsAccount saver2( 3000.0 );

   SavingsAccount::modifyInterestRate( .03 ); // change interest rate

   cout << "Initial balances:\nSaver 1: ";
   saver1.printBalance();
   cout << "\tSaver 2: ";
   saver2.printBalance();

   saver1.calculateMonthlyInterest();
   saver2.calculateMonthlyInterest();

   cout << "\n\nBalances after 1 month's interest applied at .03:\n"
      << "Saver 1: ";
   saver1.printBalance();
   cout << "\tSaver 2: ";
   saver2.printBalance();

   SavingsAccount::modifyInterestRate( .04 ); // change interest rate
   saver1.calculateMonthlyInterest();
   saver2.calculateMonthlyInterest();

   cout << "\n\nBalances after 1 month's interest applied at .04:\n"
      << "Saver 1: ";
   saver1.printBalance();
   cout << "\tSaver 2: ";
   saver2.printBalance();
   cout << endl;


   system("pause");
   return 0;
} 
//end of main

----------

~Jeff

It would be easier to go through your code if it had CODE-tags.

Anyway, I couldn't see what the problem was unless you are trying to compile the :S - smiles.
So I tried changing the smiles into just :S and it compiled fine. It could be that some file isn't included in your project or similar.

I use to have this kinda problem with VC, so try cleaning the project, You have an option of clean build try clicking that, it should work.

setted up the project folder again, It worked! Thanks! :S

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.