Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
October 11th, 2006, 08:14 PM
 soory
Registered User

Join Date: Oct 2006
Posts: 1
Time spent in forums: 5 m 50 sec
Reputation Power: 0
Simple Integer Average

Here is the script I have so far.... the question is on the bottom. Any idea how to finish it?

#!/usr/bin/perl -w
\$count = 0;
\$avg = 0;
while ((print "enter line:"),(\$line = <STDIN>) !~ /^\s*quit\s*\$/i)
{
if(\$line =~ /^\s*\$/)
{
next;
}
if(\$line !~ /^\s*([+-]?\d+)\s*?([+-]?\d*)\s*\$/)
{
print "ERROR! Pls enter valid data:\n";
next;
}
print "\$1 \$2";
if(defined(\$2))
{
if(\$2 !~ /^[+-]?\d+\$/)
{
\$tot = \$1 ;

}
else
{
\$tot = \$2;
\$count++;

}

}
\$count++;

}
if(\$count != 0)
{
\$ave = \$tot/\$count;
print "The total numbers entered = \$count";
print "the average = \$ave";
}

**************************************************************************8
QUESTION BELOW

write a pearl script with a "quit" loop . On each line of input,the user may
enter 1 or 2 integer tokens which may be signed. Compute the average of
integers from the correctly entered lines. Use the same input rules as
problem #1. Present the average on the screen .. if there is one to be
computed!!

Dont worry about the number of digits displayed in the averaqge.
Hint:can use perl function defined().

Rules.
a) it will allow lines to be entered until the user enters "quit"
b)
If user enters an empty line ,simply repromt with no error message.
c)If the user enters an invalid line reprompt after giving error msg.

d)Valid lines will have the one or two tokens described and may have any
amount of whitespace before/between/after the two tokens.

e) After the user quits out of the loop, present all of the valid first
tokens from valid lines (one per line), then all of the valid second tokens
from the valid lines (one per line), and the number of valid lines.

#2
October 11th, 2006, 08:25 PM
 Axweildr
'fie' on me, allege-dly

Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,886
Time spent in forums: 4 Months 2 Weeks 1 Day 23 h 1 m 25 sec
Reputation Power: 6443
OK, this is homework, and you couldn't be bothered to tell us where you think the problem is, or how you'd like to go about solving it ... c'mon, you would have had a better chance getting help if you made an effort ...
__________________
--Ax
without exception, there is no rule ...
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones

09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE

#3
October 11th, 2006, 09:12 PM
 Hero Zzyzzx
11

Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 82
Happy birthday. Should be easy to explain to your professor.
Code:
`perl -e '@a;@b;while(chomp(\$i=<STDIN>)&&\$i!~m/quit/i){next unless \$i;if(\$i=~m/[^\d-\s]/){print"error\n";next}@i=split(/\s+/,\$i);my\$f;map{\$f+=\$_}@i;if(@i==2){print\$f/@i."\n";push@a,\$i[0];push@b,\$i[1];}}print map{"\$_\n"}"first",@a,"second",@b,"total",scalar @a'`

And yes - it works to the requirements of the assignment.
Comments on this post
Axweildr agrees:

 Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Simple Integer Average

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |