Hello Deadweight77,
As
keskiverto pointed out and these days "double" is the preferred floating point type. But even with a "double" there are problems with its use. Not all decimal numbers are stored as entered. When I was testing it out "0.03" actually stored as "0.029999999999999999". This may not seem like a problem and it is not when you just output the number to two decimal places because it will round up to "0.03". But in many calculations this will likely give you a result that is off by a penny or two.
It has been about a year or more, but I did read in a post that in the real world when working with money neither a "float" or "double" is used, but an "int". I may not have the complete understanding of this, but what I have done has worked for me so far.
The variable is based on one(1) equals one(1) penny, so 100 would be one dollar and $1.25 would be 125. Since you do not use a decimal number there is no problem. I will show you later how to pring it out.
You have a good start with you input in main. You just need to follow through with it.
In the class I would consider doing this, although I have not changed your code yet, I feel it is a start:
1 2 3 4
|
private:
int m_balance;
};
|
My initial check did not find where "D_balance" was ever used. You may have had an idea for future use of this variable. In that case you can keep it. The "int dollars" and int cents" are not really needed. And as I have seen many times the "m_" prefix is often for class member variables and it does have its advantage.
The function "deposit" can be shortened to:
1 2 3 4 5 6 7
|
void SavingsAccount::deposit(int d, int c)
{
m_balance += (d + c);
//total_money=???
total();
}
|
I have not worked on the "withdraw" function yet, but it would be similar.
The function call to "total" has no parameters because you will be using "m_balance" from the class.
"total" which I might consider calling "printBalance" the "cout" statement would be something like this:
std::cout << "\n Your balance is: $" << m_balance / 100 << '.' << m_balance % 100 << '\n" << std::endl;
I do believe that this should work, but I still need to make the changes to your code and test it.
I feel that I may have missed something, so if you have any questions about this let me know.
Hope that helps,
Andy