From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: random number? Date: Thu, 28 Aug 1997 19:11:36 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 33 Message-ID: <3405CD68.6BAA@cs.com> References: <33F3CA35 DOT 29B3 AT erols DOT com> <33F4D7FB DOT 74A2 AT cs DOT com> <5u35ct$upr$1 AT kurica DOT wt DOT com DOT au> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp215.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Robert Debeljakovic wrote: > > I typed this one in, and the following happened: > How many dice? 1 > How many sides 10 > The result is -1892526920 > > That must have been one helluva roll eh? > > Anyone know why I get this answer? > I have checked the code? Its fine! (what little there is!) No, it isn't. Please allow me to blush with humiliation, for I made a silly mistake. Observe the following lines: printf( "How many dice? " ); scanf( "%d", n ); printf( "How many sides? " ); scanf( "%d", s ); Note the arguments to scanf(). Put ampersands before n and s (&n, &s), and the program will work fine. When you compile with '-Wall', you catch these sorts of things. Sorry. ;) -- --------------------------------------------------------------------- | John M. Aldrich | "Sin lies only in hurting other | | aka Fighteer I | people unnecessarily. All other | | mailto:fighteer AT cs DOT com | 'sins' are invented nonsense." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------