Posted: Tue Jan 24, 2012 9:42 pm Post subject: How to show a sum of numbers?
What is it you are trying to achieve?
I am trying to make a program on turing that gets a positive integer and shows the sum of numbers less than or equal to it
What is the problem you are having?
trying to display the sum of numbers
Sponsor Sponsor
Aange10
Posted: Tue Jan 24, 2012 10:22 pm Post subject: RE:How to show a sum of numbers?
That's interesting.
put is usually a good command for displaying purposes.
Velocity
Posted: Wed Jan 25, 2012 12:00 am Post subject: RE:How to show a sum of numbers?
get pint
For decreasing i : pint .. 1
Put pint + i
end for
Grade 1 math.
Dreadnought
Posted: Wed Jan 25, 2012 12:56 am Post subject: Re: How to show a sum of numbers?
@velocity If you're going to post something saying how easy the solution is (grade 1 math), at least make sure you give a solution to the actual problem.
It was asked to print the cumulative sum of all number (I assume positive integers) less than or equal to the positive integer entered. You displayed the sum of the integer entered and each individual number less than or equal to it.
I think Reading's taught in grade 1 too.
But to be on topic, to sum up these numbers you should use a for loop and a variable to serve as an accumulator (a value to which you add).
As velocity showed, you can iterate over all numbers less than or equal to a positive integer using a subrange like 1 .. maxInt .
Here's a link to a tutorial on basics of Turing you might need,
Here's a link to a tutorial on loops and for loops.
Tony
Posted: Wed Jan 25, 2012 1:05 am Post subject: Re: How to show a sum of numbers?
Dreadnought @ Wed Jan 25, 2012 12:56 am wrote:
But to be on topic, to sum up these numbers you should use a for loop and a variable to serve as an accumulator (a value to which you add).