total numbers of numbers input , largest number and smallest number and average of numbers

total numbers of numbers input , largest number and smallest number and average of numbers

Post by masterofal » Sat, 11 Feb 2006 01:49:51


so far i got some of the program but i can't figure out how to get the
greatest and smallest number from the series of number

"program that recieves as input a sries of numbers. at the end of the
input list , the program should output the total numbers of numbers
input, the largest number, smallest number and the average of all the
numbers.

thanks alot to anyone that helps me out

#!usr/loacl/bin/perl

$total = 0;
$numcounter = 0;
$largest= $number;

print "Enter a number or enter end: ";
chomp ( $number = <STDIN> );


until ($number eq "end")
{
$numcounter++;
$total += $number;
print "Enter a number or enter end: ";
chomp ( $number = <STDIN> );
}

if ( $numcounter != 0)
{

$average = $total / $numcounter;

print " \nTotal numbers inputed $numcounter";
print " \n The averaged is $average.\n ";

}
 
 
 

total numbers of numbers input , largest number and smallest number and average of numbers

Post by Paul Lall » Sat, 11 Feb 2006 03:09:50


I sincerely doubt that shebang is correct. "local" is misspelled, and
you forgot the beginning /


You forgot:
use strict;
use warnings;

If your instructor did not tell you to put those at the top of every
program, drop the course and demand your money back.


What do you think that's doing? $number doesn't exist. So it's
undefined. So is $largest. What was the point of that?


Okay, here you're incrementing the total number of numbers


Here you're keeping a running total of all the numbers.


Here you find the average of the numbers.


So where's your code that attempts to do the rest? What have you
*tried* to find the largest and smallest numbers? How did it fail?
Where did you get stuck?

Make an attempt, and then ask for help if it doesn't work. No one is
too likely to write your homework for you.

Paul Lalli