Question: I am new in learning powershell and hoping to further my experience in other programs eventually. Currently doing a course in It and in my powershell class lopps have become a bit of an enemy of mine. In one script that we have to make, we need to create a script that will add numbers inputted in an array after the click of a button, in this scenario that button with be '0'. I have attempted various scripts but keep getting errors any help would be much appreaciated and keep in mind that i am new so the simpler the response for now the best it will help me and if possible explain why my code is wrong 

```
Do {

    $input = Read-Host 'Enter variety of numbers and press 0 to add them together'

    if ($input -eq '0') {
        $sum = [int]$sum + ',' + [int]$sum
        Write-Host 'Sum of numbers entered' $sum
    }

}
while ($input -ne '0')

```

Answer: 
First off, `$input` is an [automatic variable](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6), so using it for user input is going to cause unexpected behavior.

Minding that, the Powershellish way is to use built-in cmdlets, such as `Measure-Object` that can sum things. Like so,

```
$i = Read-Host 'Enter variety of numbers, separated by space. Press <Enter> to add them together'
Write-host "The grand total is" ($i -split ' '  | measure-object -sum).sum

```

The input is read as a string into `$i`. Since string itself is a bit hard to sum, `-split` operator is used to split it into multiple things. A space `' '` is used as separator on which to split. The result is an array of objects that is piped to `Measure-Object`. It's smart enough to figure out that the things are actually integers, so summing makes sense. As the cmdlet returns multiple figures about its input, `.sum` is used to access only the sum.
The variable $input is a reservd powershell variable ([take a look here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6)) and you should not use it in this context.  

As in the comments mentiond I would also put an else in your loop and save the input to an array.

```
[System.Int32[]]$UserInputs = @() #INT Array
do {

    [System.Int32]$UserInput = Read-Host -Prompt 'Enter variety of numbers and press 0 to add them together'

    if ($UserInput -eq 0)
    {
        Out-Host -InputObject ('Sum of numbers entered ' + ($UserInputs | Measure-Object -Sum).Sum) #Return the sum
    }
    else
    {
        $UserInputs += $UserInput #Add user input to array
    }
}
while ($UserInput -ne 0)

```