Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stuck ! help needed :)

Status
Not open for further replies.

AlexisFr

Programmer
Jun 12, 2017
1
GB
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

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)]
}

 
finally found a solution but can not delete the subject !!

You can use the 'Report' link at the bottom right of the post

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top