Advertisement
Guest User

Oel - Beispiel-Logik

a guest
Sep 10th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.59 KB | None | 0 0
  1. float oilPrice[34] = { 1.1f, 1.7f, 1.8f, 1.8f, 1.6f, 1.6f, 1.1f, 1.7f, 1.1f, 1.6f, 1.4f, 0.7f, 1.2f, 1.6f, 1.7f, 1.8f, 1.2f,
  2.                        0.5f, 0.2f, 0.8f, 1.3f, 1.4f, 1.9f, 1.9f, 2.0f, 2.0f, 2.0f, 1.3f, 1.2f, 0.7f, 0.1f, 0.1f, 0.4f, 0.5f };
  3.  
  4. int main(void) {
  5.     int i;
  6.     int sellAmount;
  7.     int basicPumpCapacity = 8000;
  8.     int basicTransportCapacity = 7000;
  9.     int gameRound = 0;
  10.     int playerNum = 0;
  11.     int oilWell = 0;
  12.     int cumPumpCap[12];
  13.     int playerMoney[6];
  14.     int pumpAmount[12];
  15.     int tankWagonAmount[12];
  16.     int pumpCapacity[12];
  17.     int transportCapacity[12];
  18.    
  19.     srand((unsigned) time(NULL));
  20.     for (i = 0; i < 12; i++) {
  21.         cumPumpCap[i] = 0;
  22.         pumpAmount[i] = 0;
  23.         tankWagonAmount[i] = 0;
  24.         transportCapacity[i] = 0;
  25.     }
  26.     for (i = 0; i < 6; i++) playerMoney[i] = 124321;
  27.    
  28.     pumpCapacity[oilWell] = (rand() % 10 + 1) * basicPumpCapacity;
  29.     transportCapacity[oilWell] = (rand() % 10 + 1) * basicTransportCapacity;
  30.     cumPumpCap[oilWell] += pumpCapacity[oilWell];
  31.    
  32.     printf("Raffinerieabnahmepreis: %.1f\n\n", oilPrice[gameRound]);
  33.     /* Bis hierhin stimmmt der oilPrice */
  34.     printf("Pumpenanzahl: %d\n", pumpAmount[oilWell]);
  35.     printf("Versandmenge: %d\n", cumPumpCap[oilWell]);
  36.     printf("Tankwagen: %d\n", tankWagonAmount[oilWell]);
  37.     printf("LKW-Kapazit\x84t: %d\n", transportCapacity[oilWell]);
  38.     printf("Kapital: %d\n\n", playerMoney[playerNum]);
  39.     if (cumPumpCap[oilWell] == 0 || tankWagonAmount[oilWell] == 0) {
  40.         printf("Wieviel Liter sollen weg? ");
  41.         scanf("%d", &sellAmount);
  42.         fflush(stdin);
  43.         if (transportCapacity[oilWell] <= cumPumpCap[oilWell]) {
  44.             if (sellAmount <= transportCapacity[oilWell]) {
  45.                 printf("path 1.1\n");
  46.                 printf("sellAmount %d\n", sellAmount);
  47.                 /* Ab hier bekommt oilPrice einen absonderlichen, negativen Wert, was man in der nächsten Ausgabe sieht */
  48.                 printf("oilPrice %d\n", oilPrice[gameRound]);
  49.                 printf("transportCapacity %d\n", transportCapacity[oilWell]);
  50.                 printf("cumPumpCap %d\n", cumPumpCap[oilWell]);
  51.                 printf("sellAmount * oilPrice %d\n", sellAmount * oilPrice[gameRound]);
  52.                 cumPumpCap[oilWell] -= sellAmount;
  53.                 playerMoney[playerNum] += sellAmount * oilPrice[gameRound];
  54.             }
  55.             else {
  56.                 printf("path 1.2\n");
  57.                 printf("sellAmount %d\n", sellAmount);
  58.                 printf("oilPrice %d\n", oilPrice[gameRound]);
  59.                 printf("transportCapacity %d\n", transportCapacity[oilWell]);
  60.                 printf("cumPumpCap %d\n", cumPumpCap[oilWell]);
  61.                 printf("sellAmount * oilPrice %d\n", sellAmount * oilPrice[gameRound]);
  62.                 cumPumpCap[oilWell] -= transportCapacity[oilWell];
  63.                 playerMoney[playerNum] += sellAmount * oilPrice[gameRound];
  64.             }
  65.         }
  66.         else {
  67.             if (sellAmount <= cumPumpCap[oilWell]) {
  68.                 printf("path 2.1\n");
  69.                 printf("sellAmount %d\n", sellAmount);
  70.                 printf("oilPrice %d\n", oilPrice[gameRound]);
  71.                 printf("transportCapacity %d\n", transportCapacity[oilWell]);
  72.                 printf("cumPumpCap %d\n", cumPumpCap[oilWell]);
  73.                 printf("sellAmount * oilPrice %d\n", sellAmount * oilPrice[gameRound]);
  74.                 cumPumpCap[oilWell] -= sellAmount;
  75.                 playerMoney[playerNum] += sellAmount * oilPrice[gameRound];
  76.             }
  77.             else {
  78.                 printf("path 2.2\n");
  79.                 printf("sellAmount %d\n", sellAmount);
  80.                 printf("oilPrice %d\n", oilPrice[gameRound]);
  81.                 printf("transportCapacity %d\n", transportCapacity[oilWell]);
  82.                 printf("cumPumpCap %d\n", cumPumpCap[oilWell]);
  83.                 printf("sellAmount * oilPrice %d\n", sellAmount * oilPrice[gameRound]);
  84.                 cumPumpCap[oilWell] -= cumPumpCap[oilWell];
  85.                 playerMoney[playerNum] += sellAmount * oilPrice[gameRound];
  86.             }
  87.         }
  88.         printf("Kapital: %d\n", playerMoney[playerNum]);
  89.     }
  90.     else printf("Kein \x99l zum Verkaufen.\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement