Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.     $products = $_GET['list'];
  5.     $productsArray = explode(", ", $products);
  6.     $CPUCount = 0;
  7.     $RAMCount = 0;
  8.     $VIACount = 0;
  9.     $ROMCount = 0;
  10.     foreach ($productsArray as $product){
  11.         switch($product){
  12.             case 'CPU': $CPUCount++;
  13.                 break;
  14.             case 'RAM': $RAMCount++;
  15.                 break;
  16.             case 'ROM': $ROMCount++;
  17.                 break;
  18.             case 'VIA': $VIACount++;
  19.                 break;
  20.             default: //do nothing;
  21.                 break;
  22.         }
  23.     }
  24.     $CPUPrice = 85;
  25.     $RAMPrice = 35;
  26.     $ROMPrice = 45;
  27.     $VIAPrice = 45;
  28.     if ($CPUCount >=5 ){
  29.         $CPUPrice /= 2;
  30.     }
  31.     if ($RAMCount >=5 ) {
  32.         $RAMPrice /= 2;
  33.     }
  34.     if ($ROMCount >= 5) {
  35.         $ROMPrice /= 2;
  36.     }
  37.     if ($VIACount >= 5) {
  38.         $VIAPrice /= 2;
  39.     }
  40.     $expenses = $CPUCount*$CPUPrice + $RAMCount*$RAMPrice +
  41.         $ROMCount*$ROMPrice + $VIACount*$VIAPrice;
  42.     //this is how many computers could be assembled:
  43.     $assembledComputers = min($CPUCount, $RAMCount,
  44.         $ROMCount, $VIACount);
  45.     //....
  46.     $profitFromSoldPCs = $assembledComputers * 420;
  47.     //this is how many parts we have left:
  48.     $CPUCount -= $assembledComputers;
  49.     $RAMCount -= $assembledComputers;
  50.     $VIACount -= $assembledComputers;
  51.     $ROMCount -= $assembledComputers;
  52.     $partsLeft = $CPUCount + $RAMCount + $VIACount + $ROMCount;
  53.     //....
  54.     $profitFromPartsLeft = $CPUCount*85/2 + $RAMCount*35/2 +
  55.         $ROMCount*45/2 + $VIACount*45/2;
  56.     $profit = $profitFromSoldPCs + $profitFromPartsLeft;
  57.     $balance = $profit - $expenses;
  58.     echo "<ul><li>".$assembledComputers." computers assembled</li><li>".
  59.         $partsLeft." parts left</li></ul>";
  60.     if ($balance > 0){
  61.         echo "<p>Nakov gained ". $balance. " leva</p>";
  62.     } else {
  63.         echo "<p>Nakov lost " .$balance. " leva</p>";
  64.     }
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement