I’m an experienced programmer, I know what index out of range is, but in this instance I just cannot see the issue? I must be having a slow day! Thanks in advance to whoever can spot the bug that I seem to be missing. Amount is currently 1.45, and the denominations are 0.01, 0.05, 0.1, 0.2, 0.5 in that order in the currency array.
//currency.Length = 6 so shouldn't be an issue
int denomination = currency.Length - 1;
while (amount > 0)
{
while (amount > currency[denomination].value)
{
amount -= currency[denomination].value;
coins.Add(currency[denomination]);
yield return null;
}
denomination--;
}