Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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]
[Corion]: Hi marto ;)
[Corion]: Eily: Yeah - my French isn't even good to understand jokes, much less to make them :-D
[Corion]: marto: That post is a repost/duplicate of Excel sheet data write issue :-D
[Corion]: Whoops - Merging worksheets in .xls in one Excel sheet
[marto]: Corion, whoops, can the moderation me amended?
[Corion]: marto: We could vote, unconsider and reconsider ;)
[Corion]: "vote keep", I meant ;)
[Corion]: marto: But that aside, I hope you are well!
Corion is slowly acclimatizing to working only four days a week
[marto]: the back pain is still there, it's been a rough week, trying to do building work with a bad back

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-09-21 14:37 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (248 votes). Check out past polls.