Advertisement
Cnvmendoza

Price

Nov 12th, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <cstdlib>
  5. #include <time.h>
  6. using namespace std;
  7. //Escape add
  8. float random(float x);
  9.  
  10. //Global
  11. //Inventory
  12. int potInv = 0, oilInv = 0;
  13. int qty = 0;    //quantity
  14. int inv = 0;
  15. //User
  16. float balance = 1000;
  17. //Trade Goods Prices, in order: Sweden, Poland
  18. //Escape-add;
  19. float x;
  20. float randomnum = random(x);
  21. float potPrice[2] = { 90, 157.5 };
  22. float oilPrice[2] = { 400, 300 };
  23. float price;
  24. float priceArrays[100];
  25. //Country Mem
  26. string country = "None";    //Starting
  27. string place[2] = { "Sweden", "Poland" };
  28. int land;   //index
  29. //Country Inv (Default inv)
  30. //surplus 200%;
  31. //well-met 100%;
  32. //high 75%; med 50%; low 25%;
  33. int potInvSwede = 150, potInvPol = 50; //well 100
  34. int oilInvSwede = 25, oilInvPol = 75; //well 50
  35. int inv_Country = 0;
  36. //Goods
  37. string tradeGoods[2] = { "Pottery ", "Oil " };
  38. int goodNo;
  39. int goodType;
  40. //int remember strings
  41. int mem = 0;    //inv
  42. int mem2 = 0;   //notes
  43. int mem3 = 0;   //buy/sell
  44. //End of Global
  45. //Escape add
  46. void random(void);
  47. //What do I do first?
  48. void loc(void);
  49.  
  50. //User's Inventory
  51. void check(void);
  52.  
  53. //Trade
  54. void trade(void);
  55.  
  56. //Buy function
  57. void buy(void);
  58.  
  59. //traded
  60. void traded(void);
  61.  
  62. //Quantity function
  63. void quantity(void);
  64.  
  65. //lack function
  66. void lack(void);
  67.  
  68. //Sell function
  69. void sell(void);
  70.  
  71. //Goods function
  72. void goods(void);
  73.  
  74. //Notes function
  75. void notes(void);
  76.  
  77. //Balance function
  78. void balance_balance(void);
  79.  
  80. //todo
  81. void todo(void);
  82. void todo2(void);
  83.  
  84. //Country Inventory
  85. void countryInv(void);
  86. void determineCountry(void);
  87.  
  88. main(){
  89.     loc();
  90. }
  91.  
  92. //loc function
  93. void loc(void){
  94.     country = "None";
  95.     string input;
  96.     int x = 0;
  97.     mem = 0;
  98.     mem2 = 0;
  99.     cout << endl;
  100.     cout << endl;
  101.     cout << "Balance: " << balance;
  102.     cout << endl;
  103.     cout << "What do you want to do?";
  104.     cout << endl;
  105.     cout << "[1] Trade";
  106.     cout << endl;
  107.     cout << "[2] Check Inventory";
  108.     cout << endl;
  109.     do {
  110.         cout << "Enter Input: ";
  111.         cin >> input;
  112.         stringstream(input) >> x;
  113.         switch (x)
  114.         {
  115.             case 1:
  116.                 trade();
  117.                 break;
  118.             case 2:
  119.                 check();
  120.                 break;
  121.             default:
  122.                 cout << "That's an invalid option. Please try again.";
  123.         }
  124.         cout << endl;
  125.     } while (input != "1" || input != "2");
  126. }
  127.  
  128. //check function
  129. void check(void){
  130.     cout << endl;
  131.     cout << "You currently have:";
  132.     cout << endl;
  133.     cout << potInv << " Pottery";
  134.     cout << endl;
  135.     cout << oilInv << " Oil";
  136.     cout << endl;
  137.     cout << " ...in your inventory.";
  138.     cout << endl;
  139.     system("pause");
  140.     switch (mem){
  141.         case 0:
  142.             loc();
  143.             break;
  144.         case 1:
  145.             trade();
  146.             break;
  147.         case 2:
  148.             buy();
  149.             break;
  150.         case 3:
  151.             sell();
  152.             break;
  153.         case 4:
  154.             todo2();
  155.             break;
  156.     }
  157. }
  158.  
  159. //trade function
  160. void trade(void){
  161.     mem = 1;
  162.     string input;
  163.     country = "None";
  164.     mem2 = 1;
  165.     int x;
  166.     cout << endl;
  167.     cout << "Country List: ";
  168.     cout << endl;
  169.     cout << "[1] " << "Sweden";
  170.     cout << endl;
  171.     cout << "[2] " << "Poland";
  172.     cout << endl;
  173.     cout << "[3] " << "Check inventory";
  174.     cout << endl;
  175.     cout << "[4] " << "Check notes";
  176.     cout << endl;
  177.     cout << "[5] " << "Return";
  178.     cout << endl;
  179.     do {
  180.         cout << "Enter Input: ";
  181.         cin >> input;
  182.         stringstream(input) >> x;
  183.         switch (x){
  184.             case 1:
  185.                 land = 0;
  186.                 todo();
  187.                 break;
  188.             case 2:
  189.                 land = 1;
  190.                 todo();
  191.                 break;
  192.             case 3:
  193.                 check();
  194.                 break;
  195.             case 4:
  196.                 notes();
  197.                 break;
  198.             case 5:
  199.                 loc();
  200.                 break;
  201.             default:
  202.                 cout << "That's an invalid option. Please try again.";
  203.                 cout << endl;
  204.                 break;
  205.         }
  206.         cout << endl;
  207.     } while (input != "1" || input != "2" || input != "3" || input != "4" || input != "5");
  208. }
  209.  
  210. //goods function
  211. void goods(void){
  212.     cout << setprecision(2) << fixed;
  213.     cout << endl;
  214.     random();
  215.     cout << "[3] " << "Check inventory";
  216.     cout << endl;
  217.     cout << "[4] " << "Check notes";
  218.     cout << endl;
  219.     cout << "[5] " << "Return";
  220.     cout << endl;
  221. }
  222.  
  223. //buy function
  224. void buy(void){
  225.     string input;
  226.     int x;
  227.     mem = 2;
  228.     mem2 = 2;
  229.     mem3 = 0;
  230.     if (land == 0){
  231.         cout << endl;
  232.         cout << "You are trading with Sweden . . . ";
  233.         cout << endl;
  234.     }
  235.     else if (land == 1){
  236.         cout << endl;
  237.         cout << "You are trading with Poland . . . ";
  238.         cout << endl;
  239.     }
  240.     country = "None";
  241.     balance_balance();
  242.     goods();
  243.     cout << "What do you want to buy? ";
  244.     cout << endl;
  245.     cout << "Options: ";
  246.     cin >> input;
  247.     stringstream(input) >> x;
  248.     switch (x){
  249.         case 1:
  250.             goodType = 0;
  251.             determineCountry();
  252.             inv = potInv;
  253.             price = priceArrays[goodType];
  254.             quantity();
  255.             if (balance < qty *price){
  256.                 lack();
  257.                 break;
  258.             }
  259.             else if (balance >= qty *price){
  260.                 traded();
  261.                 break;
  262.             }
  263.  
  264.         case 2:
  265.             goodType = 1;
  266.             determineCountry();
  267.             inv = oilInv;
  268.             price = priceArrays[goodType];
  269.             quantity();
  270.             if (balance < qty *price){
  271.                 lack();
  272.                 break;
  273.             }
  274.             else if (balance >= qty *price){
  275.                 traded();
  276.                 break;
  277.             }
  278.  
  279.         case 3:
  280.             check();
  281.             break;
  282.         case 4:
  283.             notes();
  284.             break;
  285.         case 5:
  286.             trade();
  287.             break;
  288.         default:
  289.             buy();
  290.             cout << endl;
  291.     }
  292. }
  293.  
  294. //traded function
  295. void traded(void){
  296.     cout << setprecision(2) << fixed;
  297.     if (mem3 == 0){
  298.         balance -= qty * price;
  299.         balance_balance();
  300.         cout << endl;
  301.         cout << "You bought " << tradeGoods[goodType] << " for " << qty * price << ".";
  302.         cout << endl;
  303.         if (goodType==0) potInv+=qty;
  304.         else if (goodType==1) oilInv+=qty;
  305.         system("pause");
  306.         loc();
  307.     }
  308.     else if (mem3 == 1){
  309.         balance += qty * price;
  310.         balance_balance();
  311.         cout << endl;
  312.         cout << "You sold " << tradeGoods[goodType] << " for " << qty * price << ".";
  313.         cout << endl;
  314.         if (goodType==0) potInv-=qty;
  315.         else if (goodType==1) oilInv-=qty;
  316.         cout << endl;
  317.         system("pause");
  318.         loc();
  319.     }
  320. }
  321.  
  322. //quantity function
  323. void quantity(void){
  324.     mem = 4;
  325.     balance_balance();
  326.     if (mem3 == 0){
  327.         cout << "How many " << tradeGoods[goodType] << " do you want to buy? ";
  328.         cin >> qty;
  329.         countryInv();
  330.     }
  331.     else if (mem3 == 1){
  332.         cout << "How many " << tradeGoods[goodType] << " do you want to sell? ";
  333.         cin >> qty;
  334.         countryInv();
  335.     }
  336.     else quantity();
  337. }
  338.  
  339. //lacking function
  340. void lack(void){
  341.     if (mem3 == 0){
  342.         cout << endl;
  343.         cout << "You have insufficient balance . . . ";
  344.         cout << endl;
  345.         system("pause");
  346.         buy();
  347.     }
  348.     else if (mem3 == 1){
  349.         cout << endl;
  350.         cout << "You don't have " << qty << " of " << tradeGoods[goodType];
  351.         cout << endl;
  352.         system("pause");
  353.         sell();
  354.     }
  355. }
  356.  
  357. //sell function
  358. void sell(void){
  359.     string input;
  360.     int x;
  361.     mem = 3;
  362.     mem2 = 3;
  363.     mem3 = 1;
  364.     country = "None";
  365.     balance_balance();
  366.     goods();
  367.     cout << "What do you want to sell? ";
  368.     cout << endl;
  369.     cout << "Options: ";
  370.     cin >> input;
  371.     stringstream(input) >> x;
  372.     switch (x){
  373.         case 1:
  374.             goodType = 0;
  375.             inv = potInv;
  376.             price = priceArrays[goodType];
  377.             quantity();
  378.             if (inv >= qty){
  379.                 traded();
  380.                 break;
  381.             }
  382.             else if (inv < qty){
  383.                 lack();
  384.                 break;
  385.             }
  386.  
  387.         case 2:
  388.             goodType = 1;
  389.             inv = oilInv;
  390.             price = priceArrays[goodType];
  391.             quantity();
  392.             if (inv < qty){
  393.                 lack();
  394.                 break;
  395.             }
  396.             else if (inv >= qty){
  397.                 traded();
  398.                 break;
  399.             }
  400.         case 3:
  401.             check();
  402.             break;
  403.         case 4:
  404.             notes();
  405.             break;
  406.         case 5:
  407.             trade();
  408.             break;
  409.         default:
  410.             sell();
  411.     }
  412. }
  413. //notes function
  414. void notes(void){
  415.     if (country == "Sweden"){
  416.         cout << endl;
  417.         cout << "Sweden's exports and imports are well-met . . . ";
  418.         cout << endl;
  419.         //For checking . . .
  420.         cout << "Sweden's Inventory . . . ";
  421.         cout << endl;
  422.         cout << "Pottery: " << potInvSwede;
  423.         cout << endl;
  424.         cout << "Oil: " << oilInvSwede;
  425.         cout << endl;
  426.     }
  427.     else if (country == "Poland"){
  428.         cout << endl;
  429.         cout << "Poland Information . . . ";
  430.         cout << endl;
  431.         cout << "Exports: Placeholder";
  432.         cout << endl;
  433.         cout << "Imports: Placeholder";
  434.         cout << endl;
  435.         // Checking . . .
  436.         cout << "Poland's Inventory . . . ";
  437.         cout << endl;
  438.         cout << "Pottery: " << potInvPol;
  439.         cout << endl;
  440.         cout << "Oil: " << oilInvPol;
  441.         cout << endl;
  442.     }
  443.     else if (country == "None"){
  444.         cout << "Input country notes: ";
  445.         cin >> country;
  446.         notes();
  447.     }
  448.     else{
  449.         cout << "Input country notes: ";
  450.                 cin >> country;
  451.                 notes();
  452.     }
  453.     system("pause");
  454.     if (mem2 == 1) trade();
  455.     else if (mem2 == 2) buy();
  456.     else if (mem2 == 3) sell();
  457.     else if (mem2 == 4) quantity();
  458.     else if (mem2 == 5) todo2();
  459. }
  460.  
  461. //balance function
  462. void balance_balance(void){
  463.     cout << endl;
  464.     cout << setprecision(2) << fixed;
  465.     cout << "Balance: " << balance;
  466.     cout << endl;
  467. }
  468.  
  469. //todo function
  470. void todo(void){
  471.     if (land == 0){
  472.         cout << endl;
  473.         cout << "You are now trading with Sweden . . . ";
  474.         cout << endl;
  475.         todo2();
  476.     }
  477.     else if (land == 1){
  478.         cout << endl;
  479.         cout << "You are now trading with Poland . . . ";
  480.         cout << endl;
  481.         todo2();
  482.     }
  483. }
  484.  
  485. //todo2 function
  486. void todo2(void){
  487.     int x;
  488.     country = "None";
  489.     mem = 4;
  490.     mem2 = 5;
  491.     cout << endl;
  492.     cout << "[1] Buy";
  493.     cout << endl;
  494.     cout << "[2] Sell";
  495.     cout << endl;
  496.     cout << "[3] Check inventory";
  497.     cout << endl;
  498.     cout << "[4] Check notes";
  499.     cout << endl;
  500.     cout << "[5] Return";
  501.     cout << endl;
  502.     string input;
  503.     cout << "Options: ";
  504.     cin >> input;
  505.     stringstream(input) >> x;
  506.     switch (x){
  507.         case 1:
  508.             buy();
  509.             break;
  510.         case 2:
  511.             sell();
  512.             break;
  513.         case 3:
  514.             check();
  515.             break;
  516.         case 4:
  517.             notes();
  518.             break;
  519.         case 5:
  520.             trade();
  521.             break;
  522.         default:
  523.             todo();
  524.     }
  525. }
  526. //country inventory
  527. void countryInv(void){
  528.     if (land==0){
  529.         //Buy
  530.         //Buying pot
  531.         if (goodType==0 && mem3==0){
  532.             if (qty>potInvSwede){
  533.                 cout << "Sweden does not have " << qty << " pottery.";
  534.                 quantity();
  535.             }
  536.             else potInvSwede -= qty;
  537.         }
  538.         //Buying oil
  539.         else if (goodType==1 && mem3==0){
  540.             if (qty>oilInvSwede){
  541.                 cout << "Sweden does not have " << qty << " oil.";
  542.                 quantity();
  543.             }
  544.             else oilInvSwede -= qty;
  545.         }
  546.         //Sell
  547.         //Selling pot
  548.         if (goodType==0 && mem3==1){
  549.             potInvSwede += qty;
  550.         }
  551.         //Selling oil
  552.         else if (goodType==1 && mem3==1){
  553.             oilInvSwede += qty;
  554.         }
  555.     }
  556.     else if (land==1){
  557.         //Buy
  558.         if (goodType==0 && mem3==0){
  559.             if (qty>potInvPol){
  560.                 cout << "Poland does not have " << qty << " pottery.";
  561.                 quantity();
  562.             }
  563.             else potInvPol -= qty;
  564.         }
  565.         else if (goodType==1 && mem3==0){
  566.             if (qty>potInvPol){
  567.                 cout << "Poland does not have " << qty << " oil.";
  568.                 quantity();
  569.             }
  570.             oilInvPol -= qty;
  571.         }
  572.         //Sell
  573.         else if (goodType==0 && mem3==1){
  574.             potInvPol += qty;
  575.         }
  576.         else if (goodType==1 && mem3==1){
  577.             oilInvPol += qty;
  578.         }
  579.     }
  580. }
  581.  
  582.  
  583. //random function
  584. void random(void){
  585.     goodType = 0;
  586.     for (int i = 1; i <= 2; i++){
  587.         if (goodType == 0){
  588.             if (land == 0){
  589.                 inv_Country = potInvSwede;
  590.             }
  591.             else if (land == 1){
  592.                 inv_Country = potInvPol;
  593.             }
  594.            
  595.             if (inv_Country >= 76 && inv_Country >= 100){
  596.                 price = potPrice[land] + randomnum * 1;
  597.             }
  598.             else if (inv_Country >= 51 && inv_Country >= 75){
  599.                 price = potPrice[land] * 1.25 + randomnum;
  600.             }
  601.             else if (inv_Country >= 26 && inv_Country >= 50){
  602.                 price = potPrice[land] * 1.50 + randomnum;
  603.             }
  604.             else if (inv_Country > 25){
  605.                 price = oilPrice[land] * 2 + randomnum;
  606.             }
  607.             else if (inv_Country < 100){
  608.                 price = potPrice[land] * 0.5 + randomnum;
  609.             }
  610.             priceArrays[0] = price;
  611.         }
  612.         else if (goodType == 1){
  613.             if (land == 0){
  614.                 inv_Country = oilInvSwede; 
  615.             }
  616.             else if (land == 1){
  617.                 inv_Country = oilInvPol;   
  618.             }
  619.             if (inv_Country >= 38 && inv_Country >= 50){
  620.                 price = oilPrice[land] + randomnum;
  621.             }
  622.             else if (inv_Country >= 26 && inv_Country >= 37){
  623.                 price = oilPrice[land] * 1.25 + randomnum;
  624.             }
  625.             else if (inv_Country >= 13 && inv_Country >= 25){
  626.                 price = oilPrice[land] * 1.50 + randomnum;
  627.             }
  628.             else if (inv_Country >12){
  629.                 price = oilPrice[land] * 2 + randomnum;
  630.             }
  631.             else if (inv_Country < 50){
  632.                 price = oilPrice[land] * 0.75 + randomnum;
  633.             }
  634.             priceArrays[1] = price;
  635.         }
  636.         cout << "[" << i << "] " << tradeGoods[goodType] << price;
  637.         cout << endl;
  638.         goodType++;
  639.     }
  640. }
  641.  
  642. float random(float x){
  643.     srand(time(0));
  644.     x = rand() % 20 + (-20);
  645.     return x;
  646. }
  647.  
  648. //inv country function
  649. void determineCountry(void){
  650.     if (land == 0){
  651.         if (goodType == 0) inv_Country = potInvSwede;
  652.         else if (goodType == 1) inv_Country = oilInvSwede;
  653.     }
  654.     else if (land == 1){
  655.         if (goodType == 0) inv_Country = potInvPol;
  656.         else if (goodType == 1) inv_Country = oilInvPol;
  657.     }
  658. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement