

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Introduction to Pointers
incomplete
2: References
incomplete
3: Pass by Reference
incomplete
4: Pointers Quiz
incomplete
5: Nil Pointers
incomplete
6: Pointer Receivers
incomplete
7: Pointer Receiver Code
incomplete
8: Pointer Performance
incomplete
9: Update Balance
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Textio needs a new way to update user's account balance.
Implement the updateBalance function. It should take a customer pointer and a transaction, and return an error. Depending on the transactionType, it should either add or subtract the amount from the customer's balance. If the customer does not have enough money, it should return the error insufficient funds and leave the balance unchanged. If the transactionType isn't a withdrawal or deposit, it should return the error unknown transaction type. Otherwise, it should process the transaction and return nil.
alice := customer{id: 1, balance: 100.0}
deposit := transaction{customerID: 1, amount: 50, transactionType: transactionDeposit}
updateBalance(&alice, deposit)
// id: 1 balance: 150