I’ve got a quick question regarding a code I have to write. A brief description: I have to write a code about a ticket machine which will also count the money inserted and eventually return it to the customer, if he decides to cancel the process.
For the money inserted, I created a simple Array:
val money = Array(0.1, 0.2, 0.5, 1, 2, 5)
I use this Array to detect every kind of money which isn’t valid for the machine.
Furthermore, I created an empty ArrayBuffer to count all the pieces of money thrown inside:
var moneythrownin = ArrayBuffer()
And last bot not least, I have got a function to stock the type of coin tossed into the machine:
coininserted = StdIn.readLine("Please insert your money - Type 1 for 1€, etc.)
So, my problem is, that I wanted to write underneath this whole thing, that every “coin inserted” is added to the empty ArrayBuffer. So I wrote:
MoneyThrownIn += CoinInserted
The code doesn’t work, because Scala isn’t accepting my “+=” - can someone please help me?
Thanks in advance