counted loop and random number [help]
Author |
Message |
ella
![](http://compsci.ca/v3/uploads/user_avatars/12197051664ad3c772adbaf.jpg)
|
Posted: Mon Oct 12, 2009 7:13 pm Post subject: 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:
Turing: |
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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Mon Oct 12, 2009 7:44 pm Post subject: RE:counted loop and random number [help] |
|
|
code: |
if numbers = 7 then
sevens:= sevens + 1
put "Sevens: ", sevens
else
put "No sevens."
end if
|
This needs to be inside the for loop |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Oct 12, 2009 7:46 pm Post subject: RE:counted loop and random number [help] |
|
|
You probably want to check if the random number was 7 more than just once. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Mon Oct 12, 2009 7:51 pm Post subject: Re: counted loop and random number [help] |
|
|
Also don't forget to initialize the variable sevens. aka set it to zero in the beginning. |
|
|
|
|
![](images/spacer.gif) |
|
|