so i'm making a simple game and something keeps going wrong :C
the area of error is
cout << "Sales for the day are: ";
int i = 0; //declare a variable to count sales
do {
cout << " " << i;
Sleep(1000);
i = i + 1; //counts up 1 day at a time
}while(i <= numSales);
cout << "\n Your total income for the day: ";
cout << " $ " << income/100.0 << "\n\n";
system("PAUSE");
system("CLS");
// 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 is messing up :C---------------------------------------------------------------
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);
// -----------------------------------------------------------------------------
// 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 lemonade 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