delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/06/14:00:39

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Pls help!!
Date: 06 Dec 1999 09:28:40 -0800
Organization: InterWorld Communications
Lines: 27
Message-ID: <83k8msf06v.fsf@mercury.st.hmc.edu>
References: <82gnhb$dm2$1 AT imsp026 DOT netvigator DOT com>
NNTP-Posting-Host: mercury.st.hmc.edu
X-Trace: nntp1.interworld.net 944501365 7033 134.173.45.219 (6 Dec 1999 17:29:25 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 6 Dec 1999 17:29:25 GMT
X-Newsreader: Gnus v5.7/Emacs 20.4
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019