Re: Number looping
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Aug 08, 2000
- 402 views
------=_NextPart_000_0014_01C000D3.0D5445A0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Here's another way to do it: <code follows> -- program: guess a random number include get.e -- to allow use of "prompt_number" & "wait_key" integer numbah -- number to guess atom ans -- players guess object continue -- does user want to continue playing numbah=3Drand(100) while 1 do ans =3D prompt_number("Guess a number", {1,100}) -- get guess; = number range is 1 to 100 if ans<numbah then puts(1,"A little higher...") elsif ans>numbah then puts(1,"A little lower..")=20 elsif ans=3Dnumbah then puts(1,"You got it! Do you want to guess another number? (y/n)") continue =3D wait_key() -- get next key press if continue !=3D 'y' then -- anything but 'y' exits loop exit else clear_screen() end if end if end while <code ends> NOTE: "continue" had to be "object" type, "sequence" type gave type = check error; why? Dan Moyer ----- Original Message -----=20 From: Paul Kerslake=20 To: EUPHORIA at LISTSERV.MUOHIO.EDU=20 Sent: Monday, August 07, 2000 1:39 PM Subject: Number looping Does anyone know how to make a number guessing game? I think I've = pretty much got it, but I need it to go back to the beginning. Right now = it ends after you type in a number so I need to make it so that you can = keep trying to get the number. Here;s what it looks like: numbah=3Drand(100) atom ans while 1 do if ans>numbah then position(6,1) puts(1,"Your number must be lower than 100.") elsif ans<numbah then position(6,1) puts(1,"A little higher...") elsif ans>numbah then puts(1,"A little lower..") elsif ans=3Dnumbah puts(1,"You got it!") end if end while thanks =20 =20 ------=_NextPart_000_0014_01C000D3.0D5445A0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.3105.105" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3D"Times New Roman">Here's another way to do = it:</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman"><code follows></FONT></DIV> <DIV><FONT face=3D"Times New Roman">-- program: guess a random=20 number</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">include get.e -- to allow use of=20 "prompt_number" & "wait_key"</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">integer numbah -- number to=20 guess</FONT></DIV> <DIV><FONT face=3D"Times New Roman">atom=20 ans -- = players=20 guess</FONT></DIV> <DIV><FONT face=3D"Times New Roman">object continue -- does user = want to=20 continue playing</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">numbah=3Drand(100)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">while 1 do</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> ans =3D = prompt_number("Guess=20 a number", {1,100}) -- get guess; number range is 1 to 100</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> if ans<numbah=20 then</FONT></DIV> <DIV><FONT face=3D"Times New = puts(1,"A little higher...")</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> elsif = ans>numbah=20 then</FONT></DIV> <DIV><FONT face=3D"Times New = puts(1,"A little lower..") </FONT></DIV> <DIV><FONT face=3D"Times New Roman"> elsif = ans=3Dnumbah=20 then</FONT></DIV> <DIV><FONT face=3D"Times New = puts(1,"You got it! Do you want to guess another number? = (y/n)")</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> = continue=20 =3D wait_key() -- get next key press</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> = if=20 continue !=3D 'y' then -- anything but 'y' exits loop</FONT></DIV> <DIV><FONT=20 face=3D"Times New = exit</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> = else</FONT></DIV> <DIV><FONT=20 face=3D"Times New = clear_screen()</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> end=20 if</FONT></DIV> <DIV><FONT face=3D"Times New Roman"> end if</FONT></DIV> <DIV><FONT face=3D"Times New Roman">end while</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman"><code ends></FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">NOTE: "continue" had to be = "object"=20 type, "sequence" type gave type check error; why?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3D"Times New Roman">Dan Moyer</FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:paulk at UNISERVE.COM" title=3Dpaulk at UNISERVE.COM>Paul = Kerslake</A>=20 </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20 href=3D"mailto:EUPHORIA at LISTSERV.MUOHIO.EDU"=20 title=3DEUPHORIA at LISTSERV.MUOHIO.EDU>EUPHORIA at LISTSERV.MUOHIO.EDU</A> = </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, August 07, 2000 = 1:39=20 PM</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Number looping</DIV> <DIV><BR></DIV> <DIV><FONT size=3D2>Does anyone know how to make a number guessing = game? I think=20 I've pretty much got it, but I need it to go back to the beginning. = Right now=20 it ends after you type in a number so I need to make it so that you = can keep=20 trying to get the number.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Here;s what it looks like:</FONT></DIV> <DIV><FONT size=3D2><BR>numbah=3Drand(100)<BR>atom ans<BR>while 1 = do</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>if ans>numbah = then<BR>position(6,1)<BR>puts(1,"Your=20 number must be lower than 100.")<BR>elsif=20 ans<numbah = then<BR>position(6,1)<BR>puts(1,"A=20 little higher...")<BR>elsif ans>numbah then<BR>puts(1,"A little=20 lower..")</FONT></DIV> <DIV><FONT size=3D2>elsif ans=3Dnumbah</FONT></DIV> <DIV><FONT size=3D2>puts(1,"You got it!")<BR>end if<BR>end = while</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>thanks</FONT></DIV> <DIV><FONT size=3D2></FONT> </DIV> <DIV> </DIV> ------=_NextPart_000_0014_01C000D3.0D5445A0--