如何在Powershell中将数组中数字的平均值输入到Windows消息框中?

yhuiod9q  于 2023-03-18  发布在  Shell
关注(0)|答案(1)|浏览(96)

我试图让学生的平均分数显示在Windows消息框提示,输入最大5分后,从0-100我想平均输出到提示。
学生评分列表给了我学生输入的任何数字的平均值,但仍然没有显示在消息提示中。

$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
kiz8lqtg

kiz8lqtg1#

我假设您的问题是关于如何创建MessageBox,所以先不考虑循环逻辑,下面是如何创建的:

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)

相关问题