コード例 #1
0
ファイル: Server.cs プロジェクト: dasdy/ticketSeller
 //not guaranteed to work properly, but good enough
 private CoinsStatus CalcChange(int price)
 {
     if (price > Coins.GetVal()) throw new Exception("not enough cash in server");
     var coins = new CoinsStatus();
     coins = Coins - coins; // too lazy to copy objects
     while (price > 0)
     {
         if (price >= 50 && coins.amountOf50 > 0)
         {
             price -= 50;
             coins.amountOf50--;
         }
         else
         if (price >= 25 && coins.amountOf25 > 0)
         {
             price -= 25;
             coins.amountOf25--;
         }
         else
         if (price >= 10 && coins.amountOf10 > 0)
         {
             price -= 10;
             coins.amountOf10--;
         }
         else
         if (price >= 5 && coins.amountOf5 > 0)
         {
             price -= 5;
             coins.amountOf5--;
         }
         else
         if (price >= 2 && coins.amountOf2 > 0)
         {
             price -= 2;
             coins.amountOf2--;
         }
         else if (price >= 1 && coins.amountOf1 > 0)
         {
             price -= 1;
             coins.amountOf1--;
         }
         else
         {
             throw new Exception("f**k u");
         }
     }
     return coins;
 }
コード例 #2
0
ファイル: Server.cs プロジェクト: dasdy/ticketSeller
 public Server(CoinsStatus st)
 {
     S = new Semaphore(1, 1);
     Coins = st;
 }