Advertisement
presentedin4d

LemonadeStand

Feb 16th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.17 KB | None | 0 0
  1. #include<iostream>
  2. #include<Windows.h>
  3. #include<ctime>
  4. #include<string>
  5. using namespace std;
  6.  
  7. /*
  8. To-Do List:
  9. - Create a method so you can purchase things from the shop. *DONE*
  10. - Every day, randomly choose a weather condition *DONE*
  11. - Every day, let the player choose which type of lemonade to make and deplete the supplies and add the lemonade. *DONE*
  12. - Every day, let a random number of customers come to the stand and decide on buying lemonade based on the percentages in the buyChance array.*DONE*
  13. - Make a goal for making say 300 dollars by the end of the game or you lose. *DONE*
  14. - Make ASCII Art for winning / losing
  15. - Finish Losing Conditions (Not needed?)
  16. */
  17. int SLEEP_TIME = 350, GOAL = 100, DAYS_ALLOWED = 10, cups = 0, uses = 0, sugar = 0, fullCups = 0, lemons = 0, ice = 0, days = 1, customerType = 0, consecutive = 0, type, weatherIndex;
  18. double money = 30.00, chargingPrice;
  19. double prices[] = {2.00, 4.00, 5.00, 1.50};
  20. string weather[] = {"Cloudy", "Rainy", "Windy", "Dry", "Fair", "Sunny"};
  21. string types[] = {"Sweet", "Normal", "Sour"};
  22. int buyChance[3][6] = {{23, 15, 17, 35, 30, 32},{25, 19, 20, 30, 35, 27},{24, 15, 23, 37, 32, 34}}; // {Sweet, Normal, Sour} Percent Chances of Purchase
  23. //Convenient random method
  24. int ran(int min, int max) {
  25.     return min + rand() % (max - min + 1);
  26. }
  27.  
  28. void displayShop() {
  29.     Sleep(SLEEP_TIME);
  30.     string stock[] = {"5 Sugar Packets (Satisfies one pitcher of normal lemonade)", "Lemon (Satisfies one pitcher of normal lemonade)", "Ice bag (Fills 1 Pitcher)", "Stack of 30 cups (Satisfies one pitcher)", "Exit"};
  31.     cout << "General Store -- Your Money: $" << money << endl;
  32.     cout << "Your stock -- Sugar(" << sugar << "), Lemons(" << lemons << "), Ice Bags(" << ice << "), Cups(" << cups << ")" << ", Full Cups(" << fullCups << ")" << endl;
  33.     for(int index = 0; index < 5; index++) {
  34.         if(index == 4)
  35.             cout << "(5) Exit." << endl;
  36.         else
  37.             cout << "(" << index + 1 << ") " << stock[index] << " - $" << prices[index] << endl;
  38.     }
  39. }
  40.  
  41. void displayLemonade() {
  42.     Sleep(SLEEP_TIME);
  43.     cout << "Your stock: Sugar(" << sugar << "), Lemons(" << lemons << "), Ice Bags(" << ice << "), Cups(" << cups << ")" << ", Full Cups(" << fullCups << ")" << endl;
  44.     cout << "(1) Sweet Lemonade (10 sugar packets, 1 lemon, 1 bag of ice, 30 cups)" << endl;
  45.     cout << "(2) Normal Lemonade (5 sugar packets, 1 lemon, 1 bag of ice, 30 cups)" << endl;
  46.     cout << "(3) Sour Lemonade (5 sugar packets, 2 lemons, 1 bag of ice, 30 cups)" << endl;
  47.     cout << "(4) Exit." << endl;
  48. }
  49.  
  50. void make(int id) {
  51.     if(fullCups > 0 && id != type) {
  52.         cout << "You cannot make more lemonade of a different type while you already have some!" << endl;
  53.         return;
  54.     }
  55.     switch(id) {
  56.     case 1:
  57.         if(sugar >= 10 && lemons >= 1 && ice >= 1 && cups >= 30) {
  58.             sugar -= 10;
  59.             lemons--;
  60.             ice--;
  61.             cups -= 30;
  62.             fullCups += 30;
  63.             cout << "You make 30 cups of sweet lemonade." << endl;
  64.             type = 1;
  65.         }else{
  66.             cout << "You do not have enough supplies to make sweet lemonade!" << endl;
  67.         }
  68.         break;
  69.     case 2:
  70.         if(sugar >= 5 && lemons >= 1 && ice >= 1 && cups >= 30) {
  71.             sugar -= 5;
  72.             lemons--;
  73.             ice--;
  74.             cups -= 30;
  75.             fullCups += 30;
  76.             cout << "You make 30 cups of normal lemonade." << endl;
  77.             type = 2;
  78.         }else{
  79.             cout << "You do not have enough supplies to make normal lemonade!" << endl;
  80.         }
  81.         break;
  82.     case 3:
  83.         if(sugar >= 5 && lemons >= 2 && ice >= 1 && cups >= 30) {
  84.             sugar -= 5;
  85.             lemons -= 2;
  86.             ice--;
  87.             cups -= 30;
  88.             fullCups += 30;
  89.             cout << "You make 30 cups of sour lemonade." << endl;
  90.             type = 3;
  91.         }else{
  92.             cout << "You do not have enough supplies to make sour lemonade!" << endl;
  93.         }
  94.         break;
  95.     }
  96. }
  97.  
  98. void purchase(int id) {
  99.     switch(id) {
  100.     case 1:
  101.         sugar += 5;
  102.         money -= 2.00;
  103.         cout << "You buy some sugar." << endl;
  104.         break;
  105.     case 2:
  106.         lemons++;
  107.         money -= 5.00;
  108.         cout << "You buy a lemon." << endl;
  109.         break;
  110.     case 3:
  111.         ice++;
  112.         money -= 5.00;
  113.         cout << "You buy a bag of ice." << endl;
  114.         break;
  115.     case 4:
  116.         cups += 30;
  117.         money -= 1.50;
  118.         cout << "You buy a stack of 30 cups." << endl;
  119.         break;
  120.     }
  121. }
  122.  
  123. int main() {system("Color 0E");
  124. srand(time(0));
  125. system("cls");for(int x=50; x>0; x--){cout <<endl;Sleep(50);}
  126. cout <<"Welcome to the Lemonade Stand Game!\nCreated by: REDACTED and REDACTED";
  127. for(int x=10; x>0; x--){cout <<endl;Sleep(50);}
  128. system("pause");
  129. system("cls");
  130.  
  131. if(days > DAYS_ALLOWED && money < GOAL) {
  132.         system("cls");
  133.         cout << "You did not meet the required money amount by day " << DAYS_ALLOWED << ", so therefore you lose." << endl;
  134.     }
  135. if(days > DAYS_ALLOWED && money >= GOAL) {
  136.         system("cls");
  137.         cout << "You met the required money goal! You win!" << endl;
  138.     }
  139. while(days <= DAYS_ALLOWED) {
  140.     if(days > DAYS_ALLOWED && money >= GOAL) {
  141.         system("cls");
  142.         cout << "You met the required money goal! You win!" << endl;
  143.         break;
  144.     }
  145. options:
  146.     int choice = 1;
  147.     cout << "Your stock: Money(" << money << "), Sugar(" << sugar << "), Lemons(" << lemons << "), Ice Bags(" << ice << "), Cups(" << cups << ")" << ", Full Cups(" << fullCups << ")" << endl;
  148.     cout << "Day: " << days << ", (1) Visit the general store. (2) Make Lemonade. (3) Start Day" << endl;
  149.     cin >> choice;
  150.     if(choice == 1)
  151.     {
  152.         system("cls");
  153.             goto store;
  154.     }
  155.     else if(choice == 2)
  156.         goto make;
  157.     else if(choice == 3) {
  158.         goto run;
  159.     }
  160.     else
  161.         goto options;
  162. store:
  163.     displayShop();
  164.     cin >> choice;
  165.     if(choice < 1 || choice > 5) {
  166.         cout << "You have entered in an invalid choice!" << endl;
  167.         goto store;
  168.     }else{
  169.         if(choice == 5)
  170.         {
  171.             system("cls");
  172.         goto options;
  173.         }
  174.         else {
  175.             if(money >= prices[choice - 1]) {
  176.                 purchase(choice);
  177.                 Sleep(400);
  178.                 system("cls");
  179.             }
  180.             else
  181.                 cout << "You do not have enough money to buy that!" << endl;
  182.         }
  183.         goto store;
  184.     }
  185. make:
  186.     displayLemonade();
  187.     cin >> choice;
  188.     if(choice < 1 || choice > 4) {
  189.         cout << "You have entered in an invalid choice!" << endl;
  190.         goto make;
  191.     }
  192.     if(choice == 4){
  193.         system("cls");
  194.         goto options;
  195.     }
  196.     make(choice);
  197.     Sleep(500);
  198.     system("cls");
  199.     goto make;
  200.  
  201. run:
  202.     Sleep(SLEEP_TIME);
  203.     system("cls");
  204.     weatherIndex = ran(0, 5);
  205.     cout << "The weather condition for today: " << weather[weatherIndex] << endl;
  206.     cout << "You have until day " << DAYS_ALLOWED << " to stockpile a total of $" << GOAL << "." << endl;
  207.     if(type == 2)
  208.     cout << "What do you want the price for your lemonade to be?\n (1)Cheap ($.50), (2)Normal ($.75), (3)Expensive($1.00)" << endl;
  209.     else
  210.     cout << "What do you want the price for your lemonade to be?\n (1)Cheap ($.75), (2)Normal ($1.00), (3)Expensive($1.25)" << endl;
  211.     cin >> choice;
  212.     chargingPrice = choice;
  213.     double profit = 0;
  214.     int sold = 0;
  215.     if(consecutive >= 50) {
  216.     cout << "Your customers are starting to get bored of the same lemonade flavor!" << endl;
  217.     Sleep(1000);
  218.     }
  219.     for(int customer = 0; customer < 100; customer++) {
  220.         int base = buyChance[type][weatherIndex];
  221.         int percentage = chargingPrice == 1 ? base + 4 : chargingPrice == 2 ? base : base - 11;
  222.         percentage -= consecutive >= 50 ? 10 : 0;
  223.         if(ran(0, 100) <= percentage) {
  224.             if(fullCups == 0) {
  225.                 cout << "All of your cups have been sold!\nYou're done for the day, making $" << profit <<"!" << endl;
  226.                 cout << "You spend $2.00 on stand maintenance." << endl;
  227.                 money -= 2.00;
  228.                 days++;
  229.                 Sleep(3000);
  230.                 system("cls");
  231.                 goto options;
  232.             }else{
  233.                 fullCups--;
  234.                 sold++;
  235.                 if(type == 2) {
  236.                 money += chargingPrice == 1 ? .50 : chargingPrice == 2 ? .75 : 1.00;
  237.                 profit += chargingPrice == 1 ? .50 : chargingPrice == 2 ? .75 : 1.00;
  238.                 }else{
  239.                 money += chargingPrice == 1 ? .75 : chargingPrice == 2 ? 1.00 : 1.25;
  240.                 profit += chargingPrice == 1 ? .75 : chargingPrice == 2 ? 1.00 : 1.25;
  241.                 }
  242.                 consecutive = customerType == type ? consecutive + 1 : 0;
  243.                 customerType = customerType == type ? customerType : type;
  244.                 cout << "A customer has bought a cup!\n You now have " << fullCups << " cups of lemonade left." << endl;
  245.                 Sleep(SLEEP_TIME);
  246.             }
  247.         }
  248.     }
  249.     cout << "The day is over, and you sold " << sold << " cups of lemonade, netting a profit of $" << profit << "." << endl;
  250.     cout << "You spend $2.00 on stand maintenance." << endl;
  251.     money -= 2.00;
  252.     days++;
  253.     Sleep(3000);
  254.     system("cls");
  255. }
  256. system("pause");
  257. return 0;
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement