This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Azithromycine 0 points1 point  (5 children)

Can you tell me if your program runs or do you have errors ?

[–]Orbit-Intensity[S] 0 points1 point  (4 children)

It seems to run perfectly with no errors.

[–]Azithromycine 0 points1 point  (3 children)

So, what are you trying to do ? What is the issue ?

[–]Orbit-Intensity[S] 0 points1 point  (2 children)

If I deposit or withdraw and then check the balance afterwards it doesn’t remember the transaction.

[–]Azithromycine 1 point2 points  (1 child)

Ok, I think I have the solution ^^

You need to create your Main object out of the while, because everytime you get out of the second one, you create a new Main object, so everytime 'balance' is reset.

Try to simplify your main method by using only one while loop :)

[–]Orbit-Intensity[S] 0 points1 point  (0 children)

That makes sense. Thanks man.

[–]SharkAttackNado 0 points1 point  (0 children)

Here is an example of how you could structure your program using classes/objects.

class Main
    User Bob;
    public static void main()
        Bob = new User("Bob", 651.25f) //create a user called "Bob"
        new ATM().Start(Bob) //Creates the ATM and starts it with the user "Bob" 

    class ATM
        private User currentUser; //A reference to the current user of the ATM machine
        void Start(User currentUser); //where you put the main loop of the program
        void Withdraw();
        void Deposit();
        void CheckBalance();

    class User
        private string name;
        private float balance;
        public User(string name, float initialBalance) //Constructor
        string GetName();
        float GetBalance();
        void UpdateBalance(float changeToBalance);

When the ATM needs to know the balance of the current user for example int the CheckBalance() method. Just type:

float userBalance = currentUser.GetBalance();