# How to calculate the sum of any amount of data points, regardless of amount? • ### Question

• I am trying to write a program that will calculate standard deviation (it's a statistics thing). I realize that programs such as Excel can do this for me, but I am doing this as a personal project. But, is there a way to calculate the sum of any number of data points, without knowing how many there will be before the program starts?

My code looks like this right now:

-------------------------------------------------------------------------------------------------

TextWindow.WriteLine("Enter data point # " + data + ":")
EndSub
Sub DataSum
For data = 1 To datas
datasum = datapoint[data]
EndFor
EndSub
TextWindow.WriteLine("Enter the amount of data points you have (in numeral form):")
For data = 1 To datas
For data = 1 To datas
EndFor
DataSum()
EndFor
TextWindow.WriteLine("This is your sum: " + datasum)

--------------------------------------------------------------------------------------------------------

That last line won't always be there, I wrote it for testing purposes.

Any help at all will be appreciated.

Tuesday, October 14, 2014 3:15 AM

• You can use the following program (or similar)

```stop=0
n=1
TextWindow.WriteLine(" end of input by entering nothing")
While stop=0
TextWindow.Write("enter point "+n+" : ")
If data<>0 then
sum=sum+data
sum2=sum2+data*data
n=n+1
Else
stop=1
n=n-1
EndIf
EndWhile
TextWindow.WriteLine("")
TextWindow.WriteLine("Number of points= "+n)
TextWindow.WriteLine("Total sum       = "+sum)
TextWindow.WriteLine("Sum of squares  = "+sum2)
```

Jan [ WhTurner ] The Netherlands

• Proposed as answer by Tuesday, October 14, 2014 5:33 PM
• Marked as answer by Tuesday, October 14, 2014 9:10 PM
Tuesday, October 14, 2014 3:14 PM

### All replies

• You can use the following program (or similar)

```stop=0
n=1
TextWindow.WriteLine(" end of input by entering nothing")
While stop=0
TextWindow.Write("enter point "+n+" : ")
If data<>0 then
sum=sum+data
sum2=sum2+data*data
n=n+1
Else
stop=1
n=n-1
EndIf
EndWhile
TextWindow.WriteLine("")
TextWindow.WriteLine("Number of points= "+n)
TextWindow.WriteLine("Total sum       = "+sum)
TextWindow.WriteLine("Sum of squares  = "+sum2)
```

Jan [ WhTurner ] The Netherlands

• Proposed as answer by Tuesday, October 14, 2014 5:33 PM
• Marked as answer by Tuesday, October 14, 2014 9:10 PM
Tuesday, October 14, 2014 3:14 PM
• Thank you very much, sir.

Tuesday, October 14, 2014 9:10 PM