in reply to How do I write a program that calculates the sum of all numbers to a number, n?
ORuse strict; use warnings; my $sum = 0; while(1){ print "Please input a number: "; chomp(my $number = <STDIN>); add $number to $sum; print "Your sum is now: $sum"; }
This is non usable code and used only as a reference, Good Luck!use strict; use warnings; print "Please input your string of numbers seperated by "+"; my @array = split(/[+]/, <STDIN>); my $sum = 0; foreach(@array){ add each number to the $sum } print "This is your sum: $sum";
|
|---|