BMITime Error (Chapter 19)


#1

When I attempt to assign the following in main.m of BMITime:

I receive the following error: Thread 1: EXC_ARITHMETIC(code=EXC_1386_DIV, subcode=0x0)

When I run the program each employee has $0 in assets, After googling the issue, I attempted to set randomIndex to random() % [employee count] + 1 to no avail. Does anyone know what I can do to fix this?


#2

The most likely culprit is that your employees array is probably empty or nil.

In either case, that would resolve to

The modulus operator (%) returns the remainder of a division, but in both of these cases, you end up dividing by zero if the employees array is empty (in which case [employees count] returns zero) or if it’s nil (in which case you’re sending the -count message to nil, which just returns nil*). When doing math, nil and zero are effectively the same.

Why is the second case still a division by zero? Order of operations. % beats +.

Why might your employees array be nil? Check to make sure that you have set it equal to something, such as

*not necessarily true, but true enough for our purposes


#3

No worries. The true culprit was a misplaced bracket…