INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Stuck ! help needed :)

Stuck ! help needed :)

(OP)
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

Quote (Alex)



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


RE: Stuck ! help needed :)

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close