/// <summary> /// Jonathan Sanborn /// /// Generates a value in operands range that will result in a whole number answer /// If after NUM_TRIES attempts a valid denomanator is not generated the value /// of 1 is returned in the denomantor /// </summary> /// <param name="numerator">The first operand in the division</param> /// <param name="denomanator">The Second operand in the division</param> /// <param name="opRange">The denomantors operands range</param> private void WholeNumberResult(ref int numerator, ref int denomanator, OperandsRange opRange) { int count = 0; while (numerator % denomanator > 0 && count < NUM_TRIES) { denomanator = rand.Next(opRange.rangeMin, opRange.rangeMax); denomanator = nonZeroDenominator(opRange); } if (count == NUM_TRIES) { denomanator = 1; } }
/// <summary> /// Jonathan Sanborn /// /// attempts to generate a value in the range that will result in a non negative /// answer to the passed in operand. If after NUM_TRIES a non negative result is /// not obtained then the minmum vaule of the operands range is returned. /// </summary> /// <param name="oprand1">The first operand in the subtraction</param> /// <param name="opRange">The range for the second operand</param> /// <returns>A operand that will have a non negative result or the min value of the Operands range</returns> private int nonNegativeResult(int oprand1, OperandsRange opRange) { int count = 0; int number = 0; do { number = rand.Next(opRange.rangeMin, opRange.rangeMax); count++; } while (oprand1 - number < 0 && count < NUM_TRIES); if (count == NUM_TRIES) { number = opRange.rangeMin; } return(number); }
/// <summary> /// Jonathan Sanborn & Harvey Mercado /// /// Will try to return a non zero denomitor within the passed in range /// If after NUM_TRIES a non zero value is not generated a value of one is returned /// </summary> /// <param name="opRange">The operand range that the value should be in.</param> /// <returns>A non zero value in the range or 1</returns> private int nonZeroDenominator(OperandsRange opRange) { int count = 0; int number = 0; while (number == 0 && count < NUM_TRIES) { number = rand.Next(opRange.rangeMin, opRange.rangeMax); count++; } if (count == NUM_TRIES) { number = 1; } return(number); }
/// <summary> /// Jonathan Sanborn /// /// attempts to generate a value in the range that will result in a non negative /// answer to the passed in operand. If after NUM_TRIES a non negative result is /// not obtained then the minmum vaule of the operands range is returned. /// </summary> /// <param name="oprand1">The first operand in the subtraction</param> /// <param name="opRange">The range for the second operand</param> /// <returns>A operand that will have a non negative result or the min value of the Operands range</returns> private int nonNegativeResult(int oprand1, OperandsRange opRange) { int count = 0; int number = 0; do { number = rand.Next(opRange.rangeMin, opRange.rangeMax); count++; } while (oprand1 - number < 0 && count < NUM_TRIES); if (count == NUM_TRIES) { number = opRange.rangeMin; } return number; }
/// <summary> /// Jonathan Sanborn & Harvey Mercado /// /// Will try to return a non zero denomitor within the passed in range /// If after NUM_TRIES a non zero value is not generated a value of one is returned /// </summary> /// <param name="opRange">The operand range that the value should be in.</param> /// <returns>A non zero value in the range or 1</returns> private int nonZeroDenominator(OperandsRange opRange) { int count = 0; int number = 0; while (number == 0 && count < NUM_TRIES) { number= rand.Next(opRange.rangeMin, opRange.rangeMax); count++; } if (count == NUM_TRIES) { number = 1; } return number; }