Error C2228: left of '.getWithdrawl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jennifer
    New Member
    • Apr 2012
    • 1

    Error C2228: left of '.getWithdrawl

    I cannot figure out why I am getting this error...error C2228: left of '.getWithdrawl

    Code:
    #include <iostream>
    #include <cmath>
    	using namespace std;
    
    class Account
    {
    public:
    	// The account number is
    	int id;
    	
    	// The account balance is
    	double Accountbalance;
    
    	// The current interest rate is
    	double annualInterestRate;
    
    	// Construct default account
    	Account()
    	{
    		id = 0;
    		Accountbalance = 0;
    		annualInterestRate = 0;
    	}
    
    	// Accessor function
    	int getid();
    	double getAccountbalance();
    	double getannualInterestRate();
    
    	// Mutator function
    	void setid(int);
    	void setAccountbalance(double);
    	void setannualInterestRate(double);
    
    	// Interest Rate function
    	double getMonthlyInterestRate()
    	{
    		return annualInterestRate / 12;
    	}
    
    	// Withdrawl function
    	double getWithdrawl()
    	{
    		return Accountbalance - 2500;
    	}
    	
    	// Deposit function
    	double getDeposit()
    	{
    		return Accountbalance + 3000;
    	}
    };
    
    int main ()
    {
    	int Accountid(1122);
    	double Accountbalance(20000);
    	double AnnualInterestRate(0.045);
    
    	cout << "The account id is " << Accountid << "and the begining account balance is " << Accountbalance << endl;
    	cout << "The balance after the withdrawl is " << Accountbalance.getWithdrawl() << endl;
    	cout << "The balance after the deposit is " << Accountbalance.getDeposit() << endl;
    	cout << "The monthly interest rate is " << AnnualInterestRate.getMonthlyInterestRate() << endl;
    	cout << "This account was created on 3 April 2012." << endl;
    
    	system "pause";
    	return 0;
    }
    Last edited by Niheel; Apr 4 '12, 05:44 AM. Reason: code tags added
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Today I learned something. declaration with setting value in first bracket is valid.

    i.e
    Code:
    int i(100);
    is valid. if you print the value of i, it will print 100.

    anyway: your problem is simple,
    you have defined Accountbalance as double.

    and you are expecting Accountbalance to act as the class object of Account.

    The fact to access the function invoked in class you must have to define the variable as the type of class

    i.e

    Account Accountbalance;

    I am not sure yet what are you trying to achieve. simply you cannot access the function of any other class from a double type object

    Comment

    Working...