Beispiel #1
0
        public double GiveChange(double price)
        {
            if (price == UserCoinsTotal())
            {
                return(0);
            }
            double Remainder             = RemainderFromUserCoins(price);
            int    NumberOfCoinsToRemove = 0;

            foreach (Coin coin in CoinStock)
            {
                if (-Remainder >= coin.Value)
                {
                    Remainder += coin.Value;
                    CoinsToReturn.Add(coin);
                    NumberOfCoinsToRemove++;
                }
            }
            CoinStock.RemoveRange(0, NumberOfCoinsToRemove);
            return(ChangeTotal());
        }
Beispiel #2
0
 private double ChangeTotal()
 {
     return(CoinsToReturn.Sum(coin => coin.Value));
 }