Re: Number looping

new topic     » goto parent     » topic index » view thread      » older message » newer message

------=_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 blink ...

  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>&nbsp;&nbsp; this is not a bad start. =
See below for=20
a slight change or two blink ...</FONT></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
  <DIV>include get.e&nbsp; -- Required for the 'get' function<BR>include =

  wildcard.e -- Required for 'lower' function</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><BR>integer&nbsp; numbah&nbsp; -- The computer's =
selection.<BR>sequence=20
  ans&nbsp;&nbsp;&nbsp;&nbsp; -- The user's guess<BR>integer tries,=20
  maxtries</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>maxtries =3D 10&nbsp; -- The maximum number of attempts =
allowed.<BR>while 1=20
  do<BR>&nbsp; clear_screen()&nbsp;-- Start with a clean screen<BR> =
&nbsp;=20
  numbah=3Drand(100) -- The computer selects a number from =
1-100<BR>&nbsp; tries =3D=20
  0&nbsp;&nbsp;-- Initialise the "attempt" counter<BR>&nbsp; while 1=20
  do<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; position(1,1)&nbsp;-- Show the user =
what to=20
  do.<BR>&nbsp;&nbsp;&nbsp; printf(1, "You have %d tries =
remaining...\n",=20
  {maxtries - tries})<BR>&nbsp;&nbsp;&nbsp; =
position(2,1)<BR>&nbsp;&nbsp;&nbsp;=20
  puts(1, "Enter a number between 1 and 100:=20
  ")<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; ans =3D get(0)&nbsp;-- Get =
the user's=20
  guess<BR>&nbsp;&nbsp;&nbsp;&nbsp;position(6,1)&nbsp;-- All messages =
will go=20
  here.<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; if ans[1] =
!=3D=20
  GET_SUCCESS then&nbsp;-- Not a =
number!<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  puts(1, "Only enter=20
  =
;&nbsp;&nbsp;&nbsp;=20
  ")&nbsp;<BR>&nbsp;&nbsp;&nbsp; elsif ans[2]&gt;100 then&nbsp; -- Too=20
  big<BR>&nbsp;&nbsp;&nbsp;&nbsp;  puts(1,"Your number must be lower =
than=20
  101.")<BR>&nbsp;&nbsp;&nbsp; elsif ans[2]&lt;1 then&nbsp; -- Too=20
  small<BR>&nbsp;&nbsp;&nbsp;&nbsp;  puts(1,"Your number must be higher =
than=20
  0.")<BR>&nbsp;&nbsp;&nbsp; elsif ans[2]&lt;numbah then -- Guess is too =

  low<BR>&nbsp;&nbsp;&nbsp;&nbsp;  puts(1,"A little=20
  =
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  ")<BR>&nbsp;&nbsp;&nbsp;&nbsp;  tries +=3D 1<BR>&nbsp;&nbsp;&nbsp; =
elsif=20
  ans[2]&gt;numbah then -- Guess is too high<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
=20
  puts(1,"A little lower...=20
  =
nbsp;&nbsp;&nbsp;&nbsp;=20
  ")<BR>&nbsp;&nbsp;&nbsp; &nbsp; tries +=3D 1<BR>&nbsp;&nbsp;&nbsp; =
elsif=20
  ans[2]=3Dnumbah then&nbsp; -- The user got it =
right.<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
   puts(1,"You got=20
  =
  ")<BR>&nbsp;&nbsp;&nbsp; &nbsp; exit&nbsp;-- Jump out of the while=20
  loop.<BR>&nbsp;&nbsp;&nbsp; end=20
  if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; if tries =
&gt;=3D=20
  maxtries then -- Check if the user has had enough=20
  goes.<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;position(7,1)<BR>&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;puts(1,"I'm afraid you've had too many tries at=20
  this.")<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;exit&nbsp;-- Jump out of the =
while=20
  loop.<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp; end=20
  while<BR>&nbsp;<BR>&nbsp; position(8,1)<BR>&nbsp; puts(1, "Do you want =
to try=20
  again? ")<BR>&nbsp; ans =3D gets(0)<BR>&nbsp; if lower(ans[1]) !=3D =
'y' -- Just=20
  look at the first character.<BR>&nbsp; then<BR>&nbsp;&nbsp;  exit -- =
Jump out=20
  and&nbsp;end the program.<BR>&nbsp; end if</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>end while</DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>if ans&gt;numbah=20
  then<BR>position(6,1)<BR>puts(1,"Your number must be lower than=20
  100.")<BR>elsif ans&lt;numbah&nbsp;&nbsp;&nbsp;&nbsp;=20
  then<BR>position(6,1)<BR>puts(1,"A little higher...")<BR>elsif =
ans&gt;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>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>thanks</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial =

------=_NextPart_000_0034_01C00109.D76619A0--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu