/************************************************************ * Program: LemonadeStand.cpp * Author: Lara Wear * Date: April 27, 2017 * Purpose: A game that allows the user to run a lemonade * stand. The goal is to try and run the business * for as many days as possible without going * bankrupt or to make a certain amount of money in a * set period of time. * 1 glass of lemonade = 250 mL water, * 1/2 lemon, * 50 mL sugar * Some things to note: * - all prices are in cents EXCEPT the profit * goal entered by the user * - 1 litre of water makes 4 glasses of lemonade * - 1 lemon makes 2 glasses of lemonade * - a 1kg bag of sugar makes 20 glasses of lemonade *************************************************************/ // Libraries // --------- #include #include #include #include #include #include #include #include "colors.h" using namespace std; // Functions // --------- int getSales(int,int); int getMaxSales(double numLemons, double numWater, double numSugar); // Start Main // ---------- int main() { // Variables // --------- int price = 0; // price of a glass of lemonade in cents int totalCash = 0; // total cash user has in cents int day = 0; // tracks number of days played double numLemons = 0; // lemons in inventory double numWater = 0; // water in inventory double numSugar = 0; // sugar in inventory int buyLemons = 0; // purchased lemons int buySugar = 0; // purchased sugar int buyWater = 0; // purchased water double incomeGoal = 0; // $ amount user wants to earn int maxDays = 0; // max # of days to play int costLemons = 0; // cost of lemons in cents int costWater = 0; // cost of one litre of water in cents int costSugar = 0; // cost of 1 kg bag of sugar in cents int totalCost = 0; // cost of total product purchased int maxGlasses = 0; // maximum # of glasses you can sell int numSales = 0; // # glasses you sell in a day int income = 0; // total income for a day int seed = 0; // seed for random generator int x = 0; // x coordinate for printing warnings int y = 0; // y coordinate for printing warnings // seed random generator // ---------------------- // intro (ascii art/animation goes here) // ------------------------------------------ // set parameters for game // ----------------------- // determine start up investment ($5-$10) // --------------------------------------- // repeat days // --------------- do { // count day // --------- // current inventory // ------------------ // set price of lemons, water and sugar // ------------------------------------ // print cost of supplies // ---------------------- // print global market warnings // ---------------------------- // Buy Sugar // --------- // Update sugar inventory and totalCash // ------------------------------------ // Buy Lemons // ---------- // Update lemon inventory and totalCash // ------------------------------------ // Buy Water // --------- // Update water inventory and totalCash // ------------------------------------ // Print max number of glasses that can be sold // -------------------------------------------- // Clear away global market warnings // ---------------------------------- // Get price of 1 glass of lemonade from user // ------------------------------------------ // Display Stand // ------------- // Determine sales for the day // -------------------------- // Record income for the day // ---------------------------- // Print sales and income for the day // ---------------------------------- // Calculate supplies left // ----------------------- // Repeats each day } while (day < maxDays); // Determine win/loss // ------------------- if (totalCash >= incomeGoal * 100) { cout << "Yay! You win. "; } // if else { cout << "Sorry. You lose. "; } // else cout << "Your goal was $" << incomeGoal << " and you made $" << totalCash / 100.0 << endl; // end program // ----------- system("PAUSE"); return 0; } // main // ----------------------------------------------------------------------------- // Function: getSales // Input: price in cents, max # glasses that can be sold // Output: Actual number of sales // Purpose: generates a number of sales based on set price and random numbers // ----------------------------------------------------------------------------- int getSales(int price, int maxGlasses) { int numSales = 0; int calcSales = 0; int randNum = rand() % 100 + 1; // formula requires prices to be between 10 cents and 3 dollars if (price < 1) price = 1; else if (price > 300) price = 300; // formula for sales calcSales = (int)((-1 / 3.0) * price) + 100; // numSales is halfway btwn randNum and calcSales int difference = randNum - calcSales; if (randNum > calcSales) numSales = randNum - (difference / 3); else numSales = calcSales - (difference / 3); if (numSales > 100) numSales = 100; return (int)(maxGlasses * (numSales / 100.0)); } // getSales // ----------------------------------------------------------------------------- // Function: getMaxSales // Input: numLemons - number of lemons in inventory // numWater - number of litres of water in inventory // numSugar - number of bags of sugar in inventory // Output: Maximum number of glasses of lemondade that can be sold // Purpose: determine how many glasses of lemonade that can be sold // ----------------------------------------------------------------------------- int getMaxSales(double numLemons, double numWater, double numSugar){ int a = int (numLemons * 2); // 2 glasses /lemon int b = int (numWater * 4); // 4 glasses / litre water int c = int (numSugar * 20); // 20 glasses / 1 kg sugar return (a < b && a < c) ? a : ((b < c) ? b : c); } // getMaxSales