PowerShell function to find the square of a number:

Question:

This is my function for finding the square of a value:

Why is the result 4444 and not 16? Thank you.

Answer:

It seems that Read-Host is returning a string, and a string times any value in powershell, results in string repeated value times. You need to make powershell treat $value as an integer. Try this:

Source:

PowerShell function to find the square of a number: by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply