|
From: William K. <nb...@so...> - 2001-08-27 20:53:38
|
I'd like people's suggestions regarding the way equations are
created in TuxMath.
Right now, I simply do the following:
eq1 = rand() % 10;
oper = rand() % NUM_OPERS; /* 4: +, -, * and / */
eq2 = rand() % 10;
I have but two special cases at this point:
if (oper is "-", and eq2 > eq1)
swap eq1 and eq2
[ in other words, in a subtraction problem, don't allow negative numbers ]
Sam has already pointed out that we probably should support negative
answers, so this one will probably go away. :)
(Question, though... should either "eq1" and/or "eq2" be allowed to be
negative? eg, " 5 x -3 = -15 " ???)
the other case is:
if (oper is "/")
while (eq2 == 0)
eq2 = rand() % 10;
[ in other words, don't try to divide by zero! :) ]
Work really needs to be done to expand this, though. We should try to
settle on exact constraints (eg, I didn't realize we'd allow negative
answers until Sam mentioned it today).
Another issue is when the player gets asked something like " 8 / 3 " :)
I really should make sure that answers for division questions come out
as whole (integer) numbers. :)
I could do a 'while' for that, but I think it might be easier (no having
to deal with prime numbers) if I simply base the "eq1" value on the "eq2".
In other words, if "eq2" is 3, then "eq1" can be "3, 6, 9, 12, 15,..."
(I suppose I can code that in right now :) )
-bill!
|