Computer Science Canada

For loop help

Author:  LupineZ [ Fri Jan 17, 2014 7:28 pm ]
Post subject:  For loop help

What is it you are trying to achieve?
<I am trying to make the calculations correct and the output correct. The output should have same color balls for the random integer part>


What is the problem you are having?
<The colors don't match on the output, which leads to mis calculation>


Describe what you have tried to solve this problem
<I tried placing the for loop at every single location>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<setscreen ("graphics:640;480")
var num1, num2 : int
num1 := 9
var guess : int


for xcount : 1 .. 7
num1 := 9

if num1 = 9 then
drawfilloval (300, 400, 10, 10, 13) %1
drawfilloval (330, 400, 10, 10, 13) %2
drawfilloval (360, 400, 10, 10, 13) %3
drawfilloval (300, 370, 10, 10, 13) %4
drawfilloval (330, 370, 10, 10, 13) %5
drawfilloval (360, 370, 10, 10, 13) %6
drawfilloval (300, 340, 10, 10, 13) %7
drawfilloval (330, 340, 10, 10, 13) %8
drawfilloval (360, 340, 10, 10, 13) %9
end if
end for


%second numbers
for icount : 1 .. 7
randomize
randint (num2, 1, 4)
if num2 = 1 then

delay (500)
drawfilloval (300, 250, 10, 10, black) %1


elsif num2 = 2 then

delay (500)
drawfilloval (300, 250, 10, 10, 13) %1
drawfilloval (330, 250, 10, 10, 13) %2
elsif num2 = 3 then

delay (500)
drawfilloval (300, 250, 10, 10, red) %1
drawfilloval (330, 250, 10, 10, red) %2
drawfilloval (360, 250, 10, 10, red) %3

elsif num2 = 4 then

delay (500)
drawfilloval (300, 250, 10, 10, yellow) %1
drawfilloval (330, 250, 10, 10, yellow) %2
drawfilloval (360, 250, 10, 10, yellow) %3
drawfilloval (300, 220, 10, 10, yellow) %4


end if


locatexy (300, 100)
get guess %user input
if guess = num1 + num2 then
locatexy (300, 50)
put "correct"
elsif guess not= num1 + num2 then
locatexy (100, 50)
put "incorrect"
end if
end for




>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>

Author:  Dreadnought [ Fri Jan 17, 2014 10:09 pm ]
Post subject:  Re: For loop help

It's not clear what is actually the problem (what is supposed to happen, what is different?). It would be nice if you could clarify what the issue is.

Maybe cls is what you're looking for?


: