Hayden Smith
5/8/2008 11:35:00 AM
My apologies for misuse of terminology: Those two conditionals are the =
particular elements that I speak of.
----- Original Message -----=20
From: Michael T. Richter=20
To: ruby-talk ML=20
Sent: Thursday, May 08, 2008 8:41 PM
Subject: Re: initial stages of scripting
On Thu, 2008-05-08 at 19:27 +0900, Hayden Smith wrote:=20
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 program a maths =
utilit which 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 =
#{number_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 <ttmrichter@gmail.com> (GoogleTalk: =
ttmrichter@gmail.com)
The only reason some people get lost in thought is because it's =
unfamiliar territory. (Paul Fix) =20