EDIT : finally found a solution but can not delete the subject !!
Hey people !
I am trying to learn on my own some TCL scripting ton improve something for my copany but as I am the only one programmer, when I am stuck, it s quite difficult to get out of this...
can you help me debugging that code?
It is suppose to : get a list of 100 numbers called randomly (numbers from 1 to 6)
Calculate how many time each number appear
put it on my screen.
It is supposed to be simple and would be easy in C or something like that but It doesn't work for some reason here... the puts inside the proc print "0 0 0 0 0 0" instead or some numbers, and there's a final error somewhere at the end of the code
Hey people !
I am trying to learn on my own some TCL scripting ton improve something for my copany but as I am the only one programmer, when I am stuck, it s quite difficult to get out of this...
can you help me debugging that code?
It is suppose to : get a list of 100 numbers called randomly (numbers from 1 to 6)
Calculate how many time each number appear
put it on my screen.
It is supposed to be simple and would be easy in C or something like that but It doesn't work for some reason here... the puts inside the proc print "0 0 0 0 0 0" instead or some numbers, and there's a final error somewhere at the end of the code
Alex said:proc throw100 {void} {
set lengthoflist 100
for {set i 0} { $i <= [expr $lengthoflist - 1]} { incr i 1} {
lappend mylist [expr {int (rand() *6 + 1 )} ]
}
return $mylist
}
proc frequency {mylist} {
set one 0
set two 0
set three 0
set four 0
set five 0
set six 0
for {set i 0} {$i<= 99} {incr i} {
set value [lindex $mylist $i]
switch $value {
1 {
puts "$i"
incr $one
}
2 {
puts "$i"
incr $two
}
3 {
puts "$i"
incr $three
}
4 {
puts "$i"
incr $four
}
5 {
puts "$i"
incr $five
}
6 {
puts "$i"
incr $six
}
default {
puts "value $i not a value beetween 1 and 6"
}
}
}
set frequencylist(0) $one
set frequencylist(1) $two
set frequencylist(2) $three
set frequencylist(3) $four
set frequencylist(4) $five
set frequencylist(5) $six
puts "$frequencylist(0) $frequencylist(1) $frequencylist(2) $frequencylist(5) $frequencylist(4) $frequencylist(5) "
return $frequencylist
}
set mycoollist [throw100 void]
set listawesome [frequency $mycoollist]
for { set index 0 } { $index < [array size listawesome] } { incr index } {
puts [ $listawesome($index)]
}