Re: Number looping
------=_NextPart_000_0034_01C00109.D76619A0
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi Paul,
this is not a bad start. See below for a slight change or two
...
include get.e -- Required for the 'get' function
include wildcard.e -- Required for 'lower' function
integer numbah -- The computer's selection.
sequence ans -- The user's guess
integer tries, maxtries
maxtries =3D 10 -- The maximum number of attempts allowed.
while 1 do
clear_screen() -- Start with a clean screen
numbah=3Drand(100) -- The computer selects a number from 1-100
tries =3D 0 -- Initialise the "attempt" counter
while 1 do
=20
position(1,1) -- Show the user what to do.
printf(1, "You have %d tries remaining...\n", {maxtries - tries})
position(2,1)
puts(1, "Enter a number between 1 and 100: ")
=20
ans =3D get(0) -- Get the user's guess
position(6,1) -- All messages will go here.
=20
if ans[1] !=3D GET_SUCCESS then -- Not a number!
puts(1, "Only enter numbers. ")=20
elsif ans[2]>100 then -- Too big
puts(1,"Your number must be lower than 101.")
elsif ans[2]<1 then -- Too small
puts(1,"Your number must be higher than 0.")
elsif ans[2]<numbah then -- Guess is too low
puts(1,"A little higher... ")
tries +=3D 1
elsif ans[2]>numbah then -- Guess is too high
puts(1,"A little lower... ")
tries +=3D 1
elsif ans[2]=3Dnumbah then -- The user got it right.
puts(1,"You got it! ")
exit -- Jump out of the while loop.
end if
=20
if tries >=3D maxtries then -- Check if the user has had enough =
goes.
position(7,1)
puts(1,"I'm afraid you've had too many tries at this.")
exit -- Jump out of the while loop.
end if
=20
end while
=20
position(8,1)
puts(1, "Do you want to try again? ")
ans =3D gets(0)
if lower(ans[1]) !=3D 'y' -- Just look at the first character.
then
exit -- Jump out and end the program.
end if
end while
=20
cheers,
Derek Parnell
dparnell @ vic.bigpond.net.au
Melbourne, Australia
----- Original Message -----=20
From: Paul Kerslake=20
To: EUPHORIA at LISTSERV.MUOHIO.EDU=20
Sent: Tuesday, August 8 2000 06:39
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_0034_01C00109.D76619A0
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.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi Paul,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> this is not a bad start. =
See below for=20
a slight change or two
...</FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
<DIV>include get.e -- Required for the 'get' function<BR>include =
wildcard.e -- Required for 'lower' function</DIV>
<DIV> </DIV>
<DIV><BR>integer numbah -- The computer's =
selection.<BR>sequence=20
ans -- The user's guess<BR>integer tries,=20
maxtries</DIV>
<DIV> </DIV>
<DIV>maxtries =3D 10 -- The maximum number of attempts =
allowed.<BR>while 1=20
do<BR> clear_screen() -- Start with a clean screen<BR> =
=20
numbah=3Drand(100) -- The computer selects a number from =
1-100<BR> tries =3D=20
0 -- Initialise the "attempt" counter<BR> while 1=20
do<BR> <BR> position(1,1) -- Show the user =
what to=20
do.<BR> printf(1, "You have %d tries =
remaining...\n",=20
{maxtries - tries})<BR> =
position(2,1)<BR> =20
puts(1, "Enter a number between 1 and 100:=20
")<BR> <BR> ans =3D get(0) -- Get =
the user's=20
guess<BR> position(6,1) -- All messages =
will go=20
here.<BR> <BR> if ans[1] =
!=3D=20
GET_SUCCESS then -- Not a =
number!<BR> =20
puts(1, "Only enter=20
=
; =20
") <BR> elsif ans[2]>100 then -- Too=20
big<BR> puts(1,"Your number must be lower =
than=20
101.")<BR> elsif ans[2]<1 then -- Too=20
small<BR> puts(1,"Your number must be higher =
than=20
0.")<BR> elsif ans[2]<numbah then -- Guess is too =
low<BR> puts(1,"A little=20
=
p; =20
")<BR> tries +=3D 1<BR> =
elsif=20
ans[2]>numbah then -- Guess is too high<BR> =
=20
puts(1,"A little lower...=20
=
nbsp; =20
")<BR> tries +=3D 1<BR> =
elsif=20
ans[2]=3Dnumbah then -- The user got it =
right.<BR> =20
puts(1,"You got=20
=
")<BR> exit -- Jump out of the while=20
loop.<BR> end=20
if<BR> <BR> if tries =
>=3D=20
maxtries then -- Check if the user has had enough=20
goes.<BR> =
position(7,1)<BR> =20
puts(1,"I'm afraid you've had too many tries at=20
this.")<BR> exit -- Jump out of the =
while=20
loop.<BR> end if<BR> =
<BR> end=20
while<BR> <BR> position(8,1)<BR> puts(1, "Do you want =
to try=20
again? ")<BR> ans =3D gets(0)<BR> if lower(ans[1]) !=3D =
'y' -- Just=20
look at the first character.<BR> then<BR> exit -- =
Jump out=20
and end the program.<BR> end if</DIV>
<DIV> </DIV>
<DIV>end while</DIV></BLOCKQUOTE>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV>
<DIV>cheers,<BR>Derek Parnell<BR>dparnell @ =
vic.bigpond.net.au<BR>Melbourne,=20
Australia</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> Tuesday, August 8 2000 =
06:39</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Number looping</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Does anyone know how to make a number =
guessing=20
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=20
so that you can keep trying to get the number.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Here;s what it looks =
like:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>numbah=3Drand(100)<BR>atom =
ans<BR>while 1=20
do</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>if ans>numbah=20
then<BR>position(6,1)<BR>puts(1,"Your number must be lower than=20
100.")<BR>elsif ans<numbah =20
then<BR>position(6,1)<BR>puts(1,"A little higher...")<BR>elsif =
ans>numbah=20
then<BR>puts(1,"A little lower..")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>elsif ans=3Dnumbah</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>puts(1,"You got it!")<BR>end =
if<BR>end=20
while</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
------=_NextPart_000_0034_01C00109.D76619A0--
|
Not Categorized, Please Help
|
|