Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: How do I do this??

by repson (Chaplain)
on Apr 08, 2001 at 15:04 UTC ( #70820=note: print w/replies, xml ) Need Help??

in reply to How do I do this??

Just one thing with your program, as I recall with standard deviations you should have the average calculated over the whole data range, not just the elements that have come before.
Here is what I would do:
my @data; my $avg; while (<IN>) { chomp; my $tmp = [split /:/]; $avg += $tmp->[1]; push @data, $tmp; } $avg /= @data; my $std = 0; for (@data) { $std += abs($_->[1] - $avg) } $std /= @data; open(OUT, ">pa5c.dat") || die ("Can't open file $!\n"); for (@data) { my $grade; my $dev = ($_->[1] - $avg) / $std; if ($dev >= 1) { $grade = 'A' } elsif ($dev >= (1/3)) { $grade = 'B' } elsif ($dev >= (-1/3)) { $grade = 'C' } elsif ($dev > -1) { $grade = 'D' } else { $grade = 'E' } print OUT join(':', $_->[0], $_->[1], $grade) . "\n"; } close OUT;
Which produces records like
Smith:70:C Jones:74:B Rider:80:A

Replies are listed 'Best First'.
Re: Re: How do I do this??
by yabba on Apr 08, 2001 at 18:37 UTC
    Thanks a lot for your help!! I ran the program and it keeps saying: Illegal division by zero at $std /= @data; Does anyone know why??

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://70820]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2016-10-23 18:08 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.