1. it adds b to a
2. it makes the value of variable a equal to the result of step 1.
Now, your function account.getBalance() returns a double.
Step 1 will be no problem, but the result of getBalance is called a temporary, it just returns a number.
You can't assign the result of step 1 to another number, only to an actual variable.
Lvalue references are, simplistically put, variable names, they are names for spaces in memory where information can be stored.
Hope that helps, let us know if you need any further help.
Hi, Thank you for your help i tried that and because of line 49 in the CDAccount::Balance function. it asks for the balance again and skips the calculations. So is there a way around the second input or am i going to need another function? Sorry about the constant questions but I want to understand this.
I think there was a misunderstanding. Your function double CDAccount::Balance (double b) accepts a parameter b, but then ignores its value. I think it was assumed that the supplied parameter would directly update the stored balance value.
You could do something like this:
1 2
double b = account.getBalance();
b += interest ;
that would carry out the arithmetic you want. But it won't be able to update the stored balance because there is currently no mechanism to do that.
oh ok then that explains why it wouldn't work. Thank you for clearing that up. I was supposed to take a struct and turn it into a class. Maybe the purpose of this lesson was to see the difference of how they access their variables. So if you want to let the user control the input of the program then its probably best to use a struct.
There's no real need to switch back to a struct. If you really wanted to, you could make the members of a class public, just like a struct, or make the members of a struct private, like a class.
It's more about doing what is most appropriate. You clearly need some way to modify the account balance, but just changing it directly would be a bad design choice, as it is just too uncontrolled. What might be more appropriate would be to implement member functions to process various transactions such as crediting or debiting the account. Adding the interest might call such a function, or might itself be implemented as a member function.
I made a member function to do the calculations but the output is "N.#J" when it should be a number of type double can someone please help me with correcting the function MatureBalance. I'm pretty sure the problem is in lines 100-108. Thank you