Ejemplo n.º 1
0
        public ChangeSolution GetChangeBankNotesAndCoins(int changeInSatang)
        {
            ChangeSolution change = new ChangeSolution();

            change.BankNotesAndCoins = new Dictionary <BankNotesAndCoinsInSatang, int>();

            change.RoundedChange = Convert.ToDouble(changeInSatang) / 100;
            changeInSatang      /= 100;
            change.HasChange     = true;

            double afterDot = change.RoundedChange - (long)change.RoundedChange;

            int thousand = GetBanks(changeInSatang, 1000);

            changeInSatang -= 1000 * thousand;
            int fiveHundred = GetBanks(changeInSatang, 500);

            changeInSatang -= 500 * fiveHundred;
            int hundred = GetBanks(changeInSatang, 100);

            changeInSatang -= 100 * hundred;
            int fifty = GetBanks(changeInSatang, 50);

            changeInSatang -= 50 * fifty;
            int twenty = GetBanks(changeInSatang, 20);

            changeInSatang -= 20 * twenty;
            int ten = GetBanks(changeInSatang, 10);

            changeInSatang -= 10 * ten;
            int five = GetBanks(changeInSatang, 5);

            changeInSatang -= 5 * five;
            int one = changeInSatang;

            if (thousand > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Thousand, thousand);
            }

            if (fiveHundred > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.FiveHundreds, fiveHundred);
            }

            if (hundred > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Hundred, hundred);
            }

            if (fifty > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fifty, fifty);
            }

            if (twenty > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Twenty, twenty);
            }

            if (ten > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Ten, ten);
            }

            if (five > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Five, five);
            }

            if (one > 0)
            {
                change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.One, one);
            }

            return(change);
        }
Ejemplo n.º 2
0
        public ChangeSolution GetChangeBankNotesAndCoins(int changeInSatang)
        {
            var change = new ChangeSolution();

            if (changeInSatang != 0)
            {
                change.HasChange         = true;
                change.RoundedChange     = Convert.ToDouble(changeInSatang) / 100;
                change.BankNotesAndCoins = new Dictionary <BankNotesAndCoinsInSatang, int>();
                int[] a = exchange(change.RoundedChange);
                if (a[0] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Thousand, a[0]);
                }
                if (a[1] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.FiveHundreds, a[1]);
                }
                if (a[2] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Hundred, a[2]);
                }
                if (a[3] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fifty, a[3]);
                }
                if (a[4] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Twenty, a[4]);
                }
                if (a[5] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Ten, a[5]);
                }
                if (a[6] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Five, a[6]);
                }
                if (a[7] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.One, a[7]);
                }
                if (a[8] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fiftieth, a[8]);
                }
                if (a[9] > 0)
                {
                    change.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.TwentyFifth, a[9]);
                }

                //     { BankNotesAndCoinsInSatang.Thousand, a[0]},
                //     { BankNotesAndCoinsInSatang.FiveHundreds, a[1]},
                //     { BankNotesAndCoinsInSatang.Hundred, a[2]},
                //     { BankNotesAndCoinsInSatang.Fifty, a[3]},
                //     { BankNotesAndCoinsInSatang.Twenty, a[4]},
                //     { BankNotesAndCoinsInSatang.Ten, a[5]},
                //     { BankNotesAndCoinsInSatang.Five, a[6]},
                //     { BankNotesAndCoinsInSatang.One, a[7]},
                //     { BankNotesAndCoinsInSatang.Fiftieth, a[8]},
                //     { BankNotesAndCoinsInSatang.TwentyFifth, a[9]},
            }

            return(change);
        }
Ejemplo n.º 3
0
        public ChangeSolution GetChangeBankNotesAndCoins(int changeInSatang)
        {
            var posCalculator = new ChangeSolution();

            posCalculator.BankNotesAndCoins = new Dictionary <BankNotesAndCoinsInSatang, int>();
            int stang                = 0;
            int money                = 0;
            int result               = 0;
            int resultStang          = 0;
            int countThousandBank    = 0;
            int countFiveHundredBank = 0;
            int countOneHundredBank  = 0;
            int countFiftyBank       = 0;
            int countTwentyBank      = 0;
            int countTenCoin         = 0;
            int countFiveCoin        = 0;
            int countOneCoin         = 0;
            int count25StangCoin     = 0;
            int count50StangCoin     = 0;

            stang       = changeInSatang - ((changeInSatang / 100) * 100);
            resultStang = stang;

            if (changeInSatang > 0)
            {
                posCalculator.HasChange     = true;
                posCalculator.RoundedChange = Convert.ToDouble(changeInSatang) / 100;

                money  = changeInSatang / 100;
                result = money;
                if (result >= 1000)
                {
                    countThousandBank = result / 1000;
                    result            = result - (countThousandBank * 1000);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Thousand, countThousandBank);
                }
                if (result >= 500)
                {
                    countFiveHundredBank = result / 500;
                    result = result - (countFiveHundredBank * 500);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.FiveHundreds, countFiveHundredBank);
                }
                if (result >= 100)
                {
                    countOneHundredBank = result / 100;
                    result = result - (countOneHundredBank * 100);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Hundred, countOneHundredBank);
                }
                if (result >= 50)
                {
                    countFiftyBank = result / 50;
                    result         = result - (countFiftyBank * 50);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fifty, countFiftyBank);
                }
                if (result >= 20)
                {
                    countTwentyBank = result / 20;
                    result          = result - (countTwentyBank * 20);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Twenty, countTwentyBank);
                }
                if (result >= 10)
                {
                    countTenCoin = result / 10;
                    result       = result - (countTenCoin * 10);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Ten, countTenCoin);
                }
                if (result >= 5)
                {
                    countFiveCoin = result / 5;
                    result        = result - (countFiveCoin * 5);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Five, countFiveCoin);
                }
                if (result >= 1)
                {
                    countOneCoin = result / 1;
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.One, countOneCoin);
                }
                if (resultStang >= 50)
                {
                    count50StangCoin = resultStang / 50;
                    resultStang      = resultStang - (count50StangCoin * 50);
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fiftieth, count50StangCoin);
                }
                if (resultStang >= 25)
                {
                    count25StangCoin = resultStang / 25;
                    posCalculator.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.TwentyFifth, count25StangCoin);
                }
            }
            return(posCalculator);
        }
Ejemplo n.º 4
0
        public ChangeSolution GetChangeBankNotesAndCoins(int changeInSatang)
        {
            var result = new ChangeSolution();

            result.HasChange         = (changeInSatang >= 0) ? true : false;
            result.RoundedChange     = (double)changeInSatang / 100;
            result.BankNotesAndCoins = new Dictionary <BankNotesAndCoinsInSatang, int>();

            var roundedChange = result.RoundedChange;

            if (roundedChange >= 1000)
            {
                var amount = (int)roundedChange / 1000;
                roundedChange -= 1000 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Thousand, amount);
            }
            if (roundedChange >= 500)
            {
                var amount = (int)roundedChange / 500;
                roundedChange -= 500 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.FiveHundreds, amount);
            }
            if (roundedChange >= 100)
            {
                var amount = (int)roundedChange / 100;
                roundedChange -= 100 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Hundred, amount);
            }
            if (roundedChange >= 50)
            {
                var amount = (int)roundedChange / 50;
                roundedChange -= 50 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fifty, amount);
            }
            if (roundedChange >= 20)
            {
                var amount = (int)roundedChange / 20;
                roundedChange -= 20 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Twenty, amount);
            }
            if (roundedChange >= 10)
            {
                var amount = (int)roundedChange / 10;
                roundedChange -= 10 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Ten, amount);
            }
            if (roundedChange >= 5)
            {
                var amount = (int)roundedChange / 5;
                roundedChange -= 5 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Five, amount);
            }
            if (roundedChange >= 1)
            {
                var amount = (int)roundedChange / 1;
                roundedChange -= 1 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.One, amount);
            }
            roundedChange *= 100;
            if (roundedChange >= 50)
            {
                var amount = (int)roundedChange / 50;
                roundedChange -= 50 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.Fiftieth, amount);
            }
            if (roundedChange >= 25)
            {
                var amount = (int)roundedChange / 25;
                roundedChange -= 25 * amount;
                result.BankNotesAndCoins.Add(BankNotesAndCoinsInSatang.TwentyFifth, amount);
            }

            return(result);
        }