Example #1
0
        public static void cashFlow(int drinkSelectionInt)
        {
            var     user           = new User();
            var     sodas          = new Sodas();
            var     vendingmachine = new vendingMachine();
            decimal drinkPrice     = Sodas.selectionPrice;
            decimal balance        = User.Balance;

            Console.Clear();
            if (balance < drinkPrice) // ask for more cash!
            {
                insertCash(drinkSelectionInt, drinkPrice, User.Balance);
            }

            if (balance > drinkPrice) // give change
            {
                User.Balance -= drinkPrice;
                decimal change = (balance - drinkPrice);
                Console.WriteLine("Your change is ${0}." +
                                  "\nEnjoy your {1}", change, sodas.DrinkList[drinkSelectionInt]);
                //back to main
            }

            if (balance == drinkPrice)
            {
                User.Balance -= drinkPrice;
                Console.WriteLine("\nEnjoy your {0}",
                                  sodas.DrinkList[drinkSelectionInt]);
                //back to main
            }
            User.Inventory.Add(sodas.DrinkList[drinkSelectionInt]);//appends newly bought soda to user inventory
            //exit to main function
        }
Example #2
0
        public static void insertCash(int selection, decimal drinkPrice, decimal userBalance)
        {
            var sodas          = new Sodas();
            var vendingmachine = new vendingMachine();
            //SETS PUBLIC PRICE VARIABLE
            decimal selectionPrice = sodas.DrinkPrices[selection];

            Console.WriteLine("\nYour selection was {0}",
                              sodas.DrinkList[selection]);
            Console.WriteLine("Your current balance is ${0}",
                              User.Balance);

            String drinkSelectionStr =
                sodas.DrinkList[selection];
            decimal inputDecimal;

            if (User.Balance >= selectionPrice)
            {
                cashFlow(selection);
            }
            while (true) //loop checks if input is valid
            {
                Console.WriteLine("Please insert ${0}",
                                  (sodas.DrinkPrices[selection] - User.Balance));
                Console.Write("\n$");
                string inputString = Console.ReadLine();
                if (decimal.TryParse(inputString, out inputDecimal))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Try again dickhead");
                    continue;
                }
            }
            User.Balance += inputDecimal;
            cashFlow(selection);
        }
Example #3
0
        static void Main(string[] args)
        {
            var vendingMachine = new vendingMachine();
            var sodas          = new Sodas();
            var user           = new User();

            while (true)
            {
                Console.Clear();
                vendingMachine.printHomeScreen();

                int selection = vendingMachine.Selection();
                if (User.Balance >= User.CurrentDrinkPrice)
                {
                    vendingMachine.cashFlow(selection);
                }
                else
                {
                    vendingMachine.insertCash(selection,
                                              sodas.DrinkPrices[selection],
                                              User.Balance);
                }

                Console.WriteLine("Would you like to buy another drink? [y/n]");

                string input = Console.ReadLine();
                if (input.ToLower() == "y" || input.ToLower() == "y ")
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
        }