static void Main(string[] args) { bool looping = true; while (looping) { Console.WriteLine("Hello there!"); bool moreInputs = true; int buyerNo = 1; int price, cost; var prices = new List <int>(); var costs = new List <int>(); string input = ""; while (moreInputs) { WriteLine($"Please enter price for buyer number {buyerNo++}: \n(Note: to stop entering prices and to start entering costs, press letter n)\n"); input = ReadLine(); if (input == "n") { moreInputs = false; input = ""; } else { price = Int32.Parse(input); if (price < 100001 && price > -1) { prices.Add(price); } else { Console.WriteLine("Price has to be between 0 and 100000, inclusive."); buyerNo--; } } } for (int i = 0; i < prices.Count;) { WriteLine($"Please enter cost for buyer number {++i}:\n"); cost = Int32.Parse(ReadLine()); if (cost < 100001 && cost > -1) { costs.Add(cost); } else { i--; Console.WriteLine("Cost has to be between 0 and 100000, inclusive."); } } var bestPrice = BestPrice.FindBestPrice(prices.ToArray(), costs.ToArray()); Console.WriteLine($"\nBest price is: {bestPrice}\n Would you like to try with another set of inputs?\n Press any key to try more inputs.\nPress x to exit the program."); if (ReadLine() == "x") { looping = false; } } }
protected void ddlScheme_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds = new DataSet(); ds = objPricelist.GetPriceListView(recid); DataSet dsScheme = new DataSet(); dsScheme = objScheme.GetSchemeView(Convert.ToInt32(ddlScheme.SelectedValue), ""); int PriceList_Id, Item_Id, Scheme_Id, MspCalc, BpCalc, MspF, BpF; float MRP, DP, MSP, BestPrice, Discounts, MspPer, BpPer; MspPer = Convert.ToSingle(dsScheme.Tables[0].Rows[0]["msp"]); BpPer = Convert.ToSingle(dsScheme.Tables[0].Rows[0]["bp"]); PriceList_Id = recid; Item_Id = Convert.ToInt32(ddlItem.SelectedValue); MRP = Convert.ToSingle(mrp_text.Text); Scheme_Id = Convert.ToInt32(ddlScheme.SelectedValue); DP = Convert.ToSingle(dprice_text.Text); MspCalc = Convert.ToInt32((MspPer / 100) * DP); BpCalc = Convert.ToInt32((BpPer / 100) * DP); MspF = Convert.ToInt32(DP - MspCalc); BpF = Convert.ToInt32(DP - BpCalc); Discounts = Convert.ToSingle(dscnt_text.Text); MSP = MspF - Discounts; BestPrice = BpF - Discounts; msp_text.Text = MSP.ToString(); bstprice_text.Text = BestPrice.ToString(); }
public void GetBestPrice_Buying_EqualTrue() { decimal buyAmount = 2.5M; Order buyOrder = new BuyingOrder(buyAmount); BestPrice bestBuy = _marketHandler.ProcessOrder(buyOrder); Assert.Equal(bestBuy.price, 870M); }
public void GetBestPrice_Selling_EqualTrue() { decimal sellAmount = 1M; Order sellOrder = new SellingOrder(sellAmount); BestPrice bestSell = _marketHandler.ProcessOrder(sellOrder); Assert.Equal(bestSell.price, 690M); }
static void Main(string[] args) { MetaMarketHandler marketHandler = new MetaMarketHandler(); decimal amount = 4.25M; Order buyOrder = new BuyingOrder(amount); BestPrice bestBuy = marketHandler.ProcessOrder(buyOrder); Console.WriteLine(bestBuy); // without data resetting, previous sell/buy will impact on future results marketHandler.ResetData(); // if we wanna re-gather data and reset existing balances decimal sellAmount = 1.67M; Order sellOrder = new SellingOrder(sellAmount); BestPrice bestSell = marketHandler.ProcessOrder(sellOrder); Console.WriteLine(bestSell); }
public ActionResult AddPrice(string price, string cost, string PriceList, string CostList) { if (price == "" && cost == "") { List <int> pricess = System.Web.Helpers.Json.Decode <List <int> >(PriceList); List <int> costss = System.Web.Helpers.Json.Decode <List <int> >(CostList); int[] prices = pricess.ToArray(); int[] costs = costss.ToArray(); BestPrice bp = new BestPrice(); int bestPrice = bp.FindBestPrice(prices, costs); string stringPricesx = string.Join(", ", prices); string stringPrices = "{" + stringPricesx + "}"; string stringCostsx = string.Join(", ", costs); string stringCosts = "{" + stringCostsx + "}"; ViewBag.stringPricesx = stringPrices; ViewBag.stringCostsx = stringCosts; ViewBag.BestPrice = bestPrice; return(View("BestPrice")); } else { List <int> pricesCount = System.Web.Helpers.Json.Decode <List <int> >(PriceList); int priceCounter; if (pricesCount == null) { priceCounter = 0; } else { priceCounter = pricesCount.Count(); } if (Int32.Parse(price) < 1 || Int32.Parse(cost) < 0 || priceCounter > 49) { if (priceCounter != 0) { List <int> pricess = System.Web.Helpers.Json.Decode <List <int> >(PriceList); List <int> costss = System.Web.Helpers.Json.Decode <List <int> >(CostList); int[] prices = pricess.ToArray(); int[] costs = costss.ToArray(); ViewBag.PriceList = pricess; ViewBag.CostList = costss; string stringPricesx = string.Join(", ", prices); string stringPrices = "{" + stringPricesx + "}"; string stringCostsx = string.Join(", ", costs); string stringCosts = "{" + stringCostsx + "}"; ViewBag.stringPrices = stringPrices; ViewBag.stringCosts = stringCosts; ViewBag.errorMessage = "Error: Price should be more than 1, cost should not be < 0 OR there is no space for more comparison (max 50)!"; return(View("Index")); } else { ViewBag.errorMessage = "Error: Price should be more than 1, cost should not be < 0 OR there is no space for more Prices!"; return(View("Index")); } } else { int priceX = Int32.Parse(price); int costX = Int32.Parse(cost); List <int> prices = System.Web.Helpers.Json.Decode <List <int> >(PriceList); List <int> costs = System.Web.Helpers.Json.Decode <List <int> >(CostList); if (prices != null && costs != null) { prices.Add(priceX); costs.Add(costX); ViewBag.PriceList = prices; ViewBag.CostList = costs; string stringPricesx = string.Join(", ", prices); string stringPrices = "{" + stringPricesx + "}"; string stringCostsx = string.Join(", ", costs); string stringCosts = "{" + stringCostsx + "}"; ViewBag.stringPrices = stringPrices; ViewBag.stringCosts = stringCosts; } else { List <int> pricess = new List <int>(); List <int> costss = new List <int>(); pricess.Add(priceX); costss.Add(costX); ViewBag.PriceList = pricess; ViewBag.CostList = costss; string stringPricesx = string.Join(", ", pricess); string stringPrices = "{" + stringPricesx + "}"; string stringCostsx = string.Join(", ", costss); string stringCosts = "{" + stringCostsx + "}"; ViewBag.stringPrices = stringPrices; ViewBag.stringCosts = stringCosts; } return(View("Index")); } } }