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

174 views Asked by At

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
1

There are 1 answers

2
Santiago Squarzon On BEST ANSWER

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)