Okay...I have no idea what's wrong here. I've been working on this forever, and can't find a solution to my problem. Oddly, my program follows my teacher's syntax flawlessly. Can any of you guys figure out what's wrong?
Here's the program:
open (INPUT, "-Tscore.dat") || die "Cannot open input file.\n";
open (OUTPUT, ">L7AOUT.txt") || die "Cannot open file.\n";
read (INPUT, $studentname, 20);
read (INPUT, $test1, 3);
read (INPUT, $test2, 3);
read (INPUT, $test3, 3);
read (INPUT, $test4, 3);
$studentname3 = substr ($studentname, 0, 3);
print OUTPUT " CLASS TEST AVERAGES\n\n";
print OUTPUT " TEST\n";
print OUTPUT "NAME OF STUDENT AVERAGE\n\n";
while ($studentname3 ne "END")
{
$avg = ($test1 + $test2 + $test3 + $test4) / 4;
$studnum = $studnum + 1;
$totavg = $totavg + $avg;
printf OUTPUT ("%-24.20s %6.2f", $studentname, $avg);
print OUTPUT "\n\n";
read (INPUT, $name, 20);
read (INPUT, $test1, 3);
read (INPUT, $test2, 3);
read (INPUT, $test3, 3);
read (INPUT, $test4, 3);
$studentname3 = substr ($studentname, 0, 3);
}
$totavg = $totavg / $studnum;
print "\n\n";
printf OUTPUT ("%-25.22s %6.2f", $studnum, $totavg);
print "Program completed Successfully.";
close INPUT;
close OUTPUT;
exit 0;
Here's "Tscore.dat":
Tom Thumb 100096093098
Mickey Mouse 088068095086
Minnie Mouse 078056088098
Donald Duck 098096078100
Tad Pole 100100100100
Mack Aroni 095067089098
Cassie Role 082045088079
Mary Martin 085096093088
Mickey Mantle 088063095086
Darryl Strawberry 078056098098
Donald Trump 098086078100
Steve Young 100078097093
Mack Truck 095067099098
Mel Gibson 082075088079
END 000000000000
Here's my Output:
CLASS TEST AVERAGES
TEST
NAME OF STUDENT AVERAGE
Tom Thumb 96.75
Mickey Mouse 532.75
6
Minnie Mouse 555.00
98
Donald Duck 68.00
100
Tad Pole 7.50
0100
Mack Aroni 405.00
89098
Cassie Role 31.75
088079
Mary Martin 129.25
6093088
Mickey Mantl 220.00
63095086
Darryl Stra 19.50
056098098
Donald Tru 2.25
8086078100
Steve You 0.25
00078097093
Mack Tru 0.00
095067099098
Mel Gib 0.00
082075088079
END 0.00
000000000000
0.00
0.00
0.00
0.00
0.00
0.00
...The 0s continue onwards towards infinty...
Any help would be very much appreciated.
My final in this class is at noon. :|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.