I am so close but I need a push in the right direction. My program works....but it doesn't compute the new interest one I change it to 5.0. Does anyone see what I'm doing wrong????
#include <iostream>
#include <iomanip>
using namespace std;
You don't have any code to recompute the "interest" variable once the rate is changed. to helios' point, changeRate() should not be a static function, nor should rate be static. And changeRate() needs to recompute the interest.
Just remove the rate initialization in the constructore. As I guess you want to see the result calculated as per changed rate 5.0 instead of 4.0, right?
As you may knew that a static variable/data is a single copy across all the instances of that class. So, your initialization of rate in the consructore would change every time an object of that class instantiated and affect all across the class.
Savings::Savings()
{
balance = 300.00;
//rate = 4.0; //comment it out and run it now
interest = balance * rate/100;
}
I would rather put the calculation part in another function like calculateRate() instead of in a constructor. The constructor should not have an initialization for any static variable.