
-----------------------------------
ella
Mon Oct 12, 2009 7:13 pm

counted loop and random number [help]
-----------------------------------
What is it you are trying to achieve?
to determine how many values of seven was created in random numbers from 1 to 20.


What is the problem you are having?
maybe something wrong with my codes and/or i'm missing some codes.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
this is what i got so far:



var numbers, sevens : int
%
put "Random numbers: "
%
for i : 1 .. 100
    randint (numbers, 1, 20)
    put numbers : 8 ..
end for
%
if numbers = 7 then
sevens:= sevens + 1
put "Sevens: ", sevens
else put "No sevens."
end if



Please specify what version of Turing you are using
Turing 4.1.1

-----------------------------------
Insectoid
Mon Oct 12, 2009 7:44 pm

RE:counted loop and random number [help]
-----------------------------------
[code]
if numbers = 7 then
    sevens:= sevens + 1
    put "Sevens: ", sevens
else 
    put "No sevens." 
end if
[/code]
This needs to be inside the for loop

-----------------------------------
Tony
Mon Oct 12, 2009 7:46 pm

RE:counted loop and random number [help]
-----------------------------------
You probably want to check if the random number was 7 more than just once.

-----------------------------------
Zren
Mon Oct 12, 2009 7:51 pm

Re: counted loop and random number [help]
-----------------------------------
Also don't forget to initialize the variable sevens. aka set it to zero in the beginning.
