I'm having trouble with private variables in a class.
I was able to solve my problem by making those variables public, however this is not what is desired. Can anyone provide some assistance?
The basic problem is with the "total" variable.
I can't use it in the function down at the very bottom sortReimbursements, but I can use it if I put the variables in the public part of the class.
How exactly do I 'get' it? My teacher went over that part really fast at the end of class and I'm just lost. I tried google, but I couldn't find exactly what I was looking for, I was probably searching wrong, I'm sorry to bother.
Never mind. I solved it. It's a rough workaround but it works. There's probably an easier way, but oh well.
I added an array in main. double totals[SIZE]
And then I grabbed the value in total from the class and put it into that array.
and then the last function changed to this.
Oh, I didn't get your reply till after I posted my solution.
But, thanks for all your help.
I'll try to implement the getter but at least I have a fall back now if that doesn't work.
Thanks again.
Total is actually the reimbursement.
I should've named it reimbursement instead, I just kinda stuck with total.
The function that you're referring to would be calcReimbursement.
Ah, I see. I'm not sure why you are storing the result in basically a temporary variable. Why don't you just have calcReimbursement return the value it got?
That is a very good question. It's just habit. My teacher told us to do that in the beginning and then she said we could just do it in the return statement and forget the temporary variable, but it stuck with me. I actually don't use temporary variables that much now, this is actually redoing an older program to work with an array of objects.