
-----------------------------------
dmitrip
Wed Feb 28, 2007 1:56 pm

&quot;Histogram&quot; in turing
-----------------------------------
hello

i am making a program where i simulate the role of a dice 100 times using a for loop and randint

now i got that to work easily but the challenge is that i need to show a "growing" histogram of numbers as the quantity of each role increases. so that 1 will go under 1 2 will go under 2 etc..
i cant figure this one out! help will be appreciated thankss

what i got so far : 

[code]

var num : int

for role : 1..100

randint(num,1,6)




end for 

put "1"..
put "2"..
put "3"..
put "4"..
put "5"..
put "6"..


[code]

-----------------------------------
rdrake
Wed Feb 28, 2007 2:24 pm

RE:&quot;Histogram&quot; in turing
-----------------------------------
For starters you're going to need variables which track the number of times a number was chosen, incrementing the particular variable each time.  Use an array.

Afterwards you can fairly easily make a histogram from that data.

-----------------------------------
dmitrip
Wed Feb 28, 2007 3:02 pm

Re: &quot;Histogram&quot; in turing
-----------------------------------
i kept on working on it and i got it to work but its not perfect because it outputs the numbers on top of each other but each number gets its own line , how can i make it that the numbers will be able to appear on the same row and now get a new line for each number.

thanks



[code ]

var num : int

for role : 1..100
delay(100)
randint(num,1,6)


if num = 1 then
put num 

elsif num = 2 then
put " "  , num 

elsif num = 3 then
put "  " , num 

elsif num = 4 then
put "   " , num 


elsif num = 5 then 
put "    " , num 

else 
put "     " , num

end if
end for 




[code ]

-----------------------------------
Clayton
Wed Feb 28, 2007 3:09 pm

Re: &quot;Histogram&quot; in turing
-----------------------------------
look up the locate() procedure to help you out.
