Mail Archives: djgpp/1999/12/06/14:00:39
"Jason Yip" <manman AT netteens DOT net> writes:
> I wrote the following program.. I want the right answer shows "Very Good",
> the wrong answer shows "No" and input again.. but why my progam like this:
> 1st answer always correct.. the 2nd answer always wrong...
> How can I solve it? Thx a lot!!
Well, here's one bug.
> printf("How much is %d times %d? ",1+(rand()%9),1+(rand()%9));
> ans=(1+(rand()%9))*(1+(rand()%9));
rand() returns a different random number every time. So you are
asking for the product of two numbers, but the answer you expect is
the product of two different numbers!
I'm not sure that this would necessarily cause the problem you
describe, but you might fix it and see if it helps.
Another small bug: If the user gets their first guess wrong, they
won't be able to quit until they get it right (since your "No, try
again" loop doesn't check for -1).
--
Nate Eldredge
neldredge AT hmc DOT edu
- Raw text -