I got an error as I have mentioned in the title.
Below is the code
#include <iostream>
using namespace std;
class SavingsAccount {
private:
double savingsBalance;
static double AnnualInterestRate;
public:
static void ModifyInterestRate(double rate) {
AnnualInterestRate = rate;
}
double calculateMonthlyInterest(double bal) {
double total, newbal;
total = (bal * AnnualInterestRate) / 12;
newbal = bal + total;
return newbal;
}
};
int main(){
SavingsAccount saver1,saver2;
double s1, s2;
SavingsAccount::ModifyInterestRate(0.03);
s1 = saver1.calculateMonthlyInterest(2000.00);
s2 = saver2.calculateMonthlyInterest(3000.00);
cout << "Monthly Interest Saver 1: " << s1 << endl;
cout << "Monthly Interest Saver 2: " << s2 << endl;
SavingsAccount::ModifyInterestRate(0.04);
s1 = saver1.calculateMonthlyInterest(2000.00);
s2 = saver2.calculateMonthlyInterest(3000.00);
cout << "Monthly Interest Saver 1: " << s1 << endl;
cout << "Monthly Interest Saver 2: " << s2 << endl;
return 0;
}
The problem is on the static double AnnualInterestRate member. I have tried to fix this for 3 hours but still cannot please help my eyes hurt.
Errors:
Error LNK2001 unresolved external symbol "private: static double SavingsAccount::AnnualInterestRate" (?AnnualInterestRate@SavingsAccount@@0NA)
Error LNK1120 1 unresolved externals