From: "Michael T. Richter" Date: 2008-05-08T19:41:33+09:00 Subject: Re: initial stages of scripting --=-ouvhzHYN1wjuMUlHCnfv Content-Type: multipart/alternative; boundary="=-2XUh7BqNNtivqJbaFR8k" --=-2XUh7BqNNtivqJbaFR8k Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 2008-05-08 at 19:27 +0900, Hayden Smith wrote: > Hi there, > I'm a relative newbie when it comes to scripting in ruby however, for a y= ear 11 project at school, it is necesary for me to program a maths utilit w= hich requests a user - elementary school aged - to add to numbers together = to reach an answer. I've effected some coding however, I'm a little stumpt = as to why the aplet is not correctly parsing through the loops. > =3D=3D=3Dscript extract starts=3D=3D > question =3D 1 > unless question =3D=3D 20 > score =3D 0 > number_of_questions =3D 0=20 > num1 =3D rand(20)=20 > num2 =3D rand(20)=20 > correct_answer =3D num1 + num2 > puts("What is #{num1} + #{num2}/?") > user_answer =3D gets.chomp!.to_i > unless user_answer =3D=3D correct_answer > puts("Sorry, that is not correct. Please try again.") =20 > user_answer =3D gets.chomp!.to_i > end > score +=3D 1 > number_of_questions +=3D 1 > question +=3D 1 > puts("Well done! That is correct.\nYou have answered #{score} out of #{n= umber_of_questions} questions correctly.") > end > exit > =3D=3D=3Dscript extract ends=3D=3D=3D What loops? I don't see any loops in there at all. I see two conditionals ("unless question =3D=3D 20" and "unless user_answer =3D=3D correct_answer") but no loops. That might be a clue. --=20 Michael T. Richter (GoogleTalk: ttmrichter@gmail.com) The only reason some people get lost in thought is because it's unfamiliar territory. (Paul Fix) --=-2XUh7BqNNtivqJbaFR8k Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, 2008-05-08 at 19:27 +0900, Hayden Smith wrote:
Hi there,
I'm a relative newbie when it comes to scripting in=
 ruby however, for a year 11 project at school, it is necesary for me to pr=
ogram a maths utilit which requests a user - elementary school aged - to ad=
d to numbers together to reach an answer. I've effected some coding however=
, I'm a little stumpt as to why the aplet is not correctly parsing through =
the loops.
=3D=3D=3Dscript extract starts=3D=3D
question =3D 1
unless question =3D=3D 20
 score =3D 0
 number_of_questions =3D 0 
 num1 =3D rand(20) 
 num2 =3D rand(20) 
 correct_answer =3D num1 + num2
 puts("What is #{num1} + #{num2}/?")
 user_answer =3D gets.chomp!.to_i
 unless user_answer =3D=3D correct_answer
  puts("Sorry, that is not correct. Please try=
 again.")  
  user_answer =3D gets.chomp!.to_i
 end
 score +=3D 1
 number_of_questions +=3D 1
 question +=3D 1
 puts("Well done! That is correct.\nYou have a=
nswered #{score} out of #{number_of_questions} questions correctly.")<=
/FONT>
end
exit
=3D=3D=3Dscript extract ends=3D=3D=3D

What loops?  I don't see any loops in there at all.  I see two co= nditionals ("unless question =3D=3D 20" and "unless user_ans= wer =3D=3D correct_answer") but no loops.

That might be a clue.

--
Michael T. Richter <ttmri= chter@gmail.com> (GoogleTalk: ttmrichter@gmail.com)
The only reason some people get lost in thought is because it's unfamili= ar territory. (Paul Fix)
--=-2XUh7BqNNtivqJbaFR8k-- --=-ouvhzHYN1wjuMUlHCnfv Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBIItjRLqyWkKVQ54QRAiBoAJ9LVMBSVs28TKb+LmB4x8HSvS42IwCgr+7A zV7zk58O6zuvzhGdqjaQobQ= =4RJG -----END PGP SIGNATURE----- --=-ouvhzHYN1wjuMUlHCnfv--