1. Number looping

------=_NextPart_000_0005_01C00074.DE7093A0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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





------=_NextPart_000_0005_01C00074.DE7093A0
        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>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=20
beginning. Right now it ends after you type in a number so I need to =
make it so=20
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 =
100.")<BR>elsif=20
ans&lt;numbah&nbsp;&nbsp;&nbsp;&nbsp; then<BR>position(6,1)<BR>puts(1,"A =
little=20
higher...")<BR>elsif ans&gt;numbah then<BR>puts(1,"A little=20
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>

------=_NextPart_000_0005_01C00074.DE7093A0--

new topic     » topic index » view message » categorize

2. 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 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 message » categorize

3. Re: Number looping

------=_NextPart_000_0006_01C0007C.3BF48840
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Paul
Where do you input ans?
 and shouldn't
"if ans>numbah then"
be
"if ans>100 then"?
and how do you propose to escape from the loop?

Bye
Martin

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

------=_NextPart_000_0006_01C0007C.3BF48840
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi Paul</FONT></DIV>
<DIV><FONT size=3D2>Where do you input ans?</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;and shouldn't</FONT></DIV>
<DIV><FONT size=3D2>"if ans&gt;numbah then"</FONT></DIV>
<DIV><FONT size=3D2>be</FONT></DIV>
<DIV><FONT size=3D2>"if ans&gt;100 then"</FONT><FONT =
size=3D2>?</FONT></DIV>
<DIV><FONT size=3D2>and how do you propose to escape from the =
loop?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Bye<BR>Martin<BR></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-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 title=3Dpaulk at UNISERVE.COM href=3D"mailto:paulk at UNISERVE.COM">Paul =
Kerslake</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3DEUPHORIA at LISTSERV.MUOHIO.EDU=20
  =
</A>=20
  </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 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_0006_01C0007C.3BF48840--

new topic     » goto parent     » topic index » view message » categorize

4. Re: Number looping

------=_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>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">&lt;code follows&gt;</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">-- program:&nbsp; guess a random=20
number</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">include get.e -- to allow use of=20
"prompt_number" &amp; "wait_key"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">integer numbah&nbsp; -- number to=20
guess</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">atom=20
ans&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- =
players=20
guess</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">object continue&nbsp; -- does user =
want to=20
continue playing</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">numbah=3Drand(100)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">while 1 do</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">&nbsp;&nbsp;&nbsp; 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">&nbsp;&nbsp;&nbsp; if ans&lt;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">&nbsp;&nbsp;&nbsp; elsif =
ans&gt;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">&nbsp;&nbsp;&nbsp; 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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
continue=20
=3D wait_key() -- get next key press</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

else</FONT></DIV>
<DIV><FONT=20
face=3D"Times New =
clear_screen()</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end=20
if</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">&nbsp;&nbsp; end if</FONT></DIV>
<DIV><FONT face=3D"Times New Roman">end while</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">&lt;code ends&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman">NOTE:&nbsp; "continue" had to be =
"object"=20
type, "sequence" type gave type check error; why?</FONT></DIV>
<DIV>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
  <DIV><FONT size=3D2>if ans&gt;numbah =
then<BR>position(6,1)<BR>puts(1,"Your=20
  number must be lower than 100.")<BR>elsif=20
  ans&lt;numbah&nbsp;&nbsp;&nbsp;&nbsp; =
then<BR>position(6,1)<BR>puts(1,"A=20
  little higher...")<BR>elsif ans&gt;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>&nbsp;</DIV>
  <DIV><FONT size=3D2>thanks</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>

------=_NextPart_000_0014_01C000D3.0D5445A0--

new topic     » goto parent     » topic index » view message » categorize

5. Re: Number looping

On Tue, 8 Aug 2000 00:53:22 -0700, Dan B Moyer wrote:

>NOTE:  "continue" had to be "object" type, "sequence" type gave type check
error; why?

because wait_key() does not return a sequence; it returns a character.
Therefore, you could also define it as type 'atom' or even type 'integer'
(since it will contain the ASCII value of the key pressed).

-- Brian

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu