You need to provide more information regarding the issue, especially your header file.
Anyways, it seems like the error is pointing to the variable balance.
You declare a variable 'double balance' in your constructor.
When you declare a variable in a function in, it's life ends when the function ends and hence you can't use it in other functions. And probably that's why it is showing the error "undeclared identifier"
In this case, you should declare "double balance" in your header file so that any other function can use that variable.
I can see that you haven't implemented your class member functions Account::deposit(), Account::withdraw(), Account::addInterest() -- instead you've implemented free functions with the same names.
#include <iostream>
usingnamespace std;
#include "Account.h"
Account::Account()
{
double balance=0; // <= should not be here as hides member variable
balance=0;
}
// <= missing constructor implementation?
Account getbalance() // <= this line is broken, too
{
return balance;
}
void deposit(double amount) // <= not a member function
{
balance+=amount;
}
void withdraw(double amount) // <= not a member function
{
balance-=amount;
}
void addInterest(double interestRate) // <= not a member function
{
balance=balance*(1+interestRate);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std; // <= should not use 'using' in a header file!
class Account
{
private:
double balance;
public:
Account();
Account(double);
double getBalance();
void deposit(double amount);
void withdraw(double amount);
void addInterest(double interestRate);
};