+ 1
Please help me. This is a bank account system program. But it is not give desire result.
3 Réponses
+ 5
There's quite a bit amiss here, but your problem is that you're creating a new bank object after each choice. You're probably expecting it to act like a static variable.
Move your bank declaration out of your choice loop (above "re:").
Edit: The reason it was a problem is because it was instantiating a new bank object with a balance of 1000 with each loop iteration. The "total" variable was being modified just fine, it's just that you were replacing the modified bank object with a new one immediately after modifying it.
If it's not clear why this happens, imagine you had something like this instead:
int x = 5;
x = 6;
Every time your program encounters this line, it declares an "x" and sets it to 5. It's the same idea with what's happening with your bank object. Even though we set it to 6 later, it will be set back to 5 when we get back to that line.
+ 1
@Squidy yes now program is run properly as I want . when I create object before (re:).
But still I am understand what is really happen.
I mean when I create object after (re: ) so wahat is effect of it on total variable. why it is give initial value. please clarify
+ 1
@Squidy Now clear thankyou😘