A few clues, you will need an infinite loop, and you will need to read and sum user input. Hope that helps

EDIT: And depending on how you want to do this, you can either set it up to accept one set of numbers per loop, or you can input them all at once with a "+" in between them like "1+2+21+46+3+5" (second example). You would need to split user input to an array, then sum the array.
use 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"; }
OR
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";
This is non usable code and used only as a reference, Good Luck!

In reply to Re: How do I write a program that calculates the sum of all numbers to a number, n? by james28909
in thread How do I write a program that calculates the sum of all numbers to a number, n? by fmny94

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.