A couple of things here ...
1) Watch out for = vs. == ... very tricky! Your first until loop won't even
eval b/c $number=999 is always true.
2) @a=$number; is not what you want... I'm not even sure what that does. You
probably want to use the push function, like so:
push @a, $number unless $number==999;
I would also encourage you to add "-w" to your shebang line (which would have
warned you against == vs. =) as well as 'use strict;'.
A few tweaks of your code and I think it's working like you want ... have fun
playing around with it - you should be able to simplify this program even
more, once you understand all the different lines and what they do. :)
until ($number==999) {
print "Please input your number:\n";
chomp($number=<STDIN>);
#@a=$number;
push @a, $number unless $number==999;
}
foreach $i (@a) {
$c+=$i;
}
if ($number=999) {
print "Your total is: $c\n"
}
__END__
Jason
If memory serves me right, on Thursday 31 January 2002 11:09, Rambog wrote:
> I am attempting a program that reads a list of numbers from the screen
> until the number 999 is read. It then prints the sum of all numbers read-
> with the exception of the 999.
>
> My code looks like:
>
> until ($number=999) {
> print "Please input your number:\n";
> chomp($number=<STDIN>);
> @a=$number;
> }
> foreach $i (@a) {
> $c+=$i;
> }
> if ($number=999) {
> print "Your total is: $c\n"
> }
>
> The program immediately terminates with and the line "Your total is:" is
> output with a a blank value. It never even prompts me to input a number.
> What am I doing wrong?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]