Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get the average of the numbers in an array into a windows message box in Powershell?

I’m trying to get the average marks for a student to display in Windows message box prompt, after entering max 5 marks from 0-100 I want the average output to the prompt.

The student mark list gives me the average of whatever number the student inputs but still doesn’t show up in the message prompt.

$NumberPattern = "[0-100]$"

do {
    $StudentMark = Read-Host "Please enter Student Mark (0-100)"
    $Count2++
    $StudentMarkList += $StudentMark
} while ($Count2 -le $Arraysize)

$StudentMarkList


$NotifyButtons2 = $Response


# **$StudentMarkList| measure -average | select average**

Add-Type -AssemblyName PresentationCore, PresentationFramework
$NotifyButtons2 = [System.Windows.MessageBoxButton]::$StudentMarkList -bor [System.Windows.MessageBoxButton]::$StudentMarkList

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I assume your question is about how you can create a MessageBox so leaving the loop logic aside, here is how:

Add-Type -AssemblyName PresentationFramework

$average = ($StudentMarkList | Measure-Object -Average).Average

[System.Windows.MessageBox]::Show(
    [string] "Average Student Mark is: $average",
    [string] "Your Title Here",
    [System.Windows.MessageBoxButton]::OK,
    [System.Windows.MessageBoxImage]::Information)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading