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

问题描述 投票:0回答:1

我正在尝试让学生的平均分数显示在 Windows 消息框提示中,在从 0-100 输入最多 5 个分数后,我想要提示的平均输出。

学生成绩单给了我学生输入的任何数字的平均值,但仍然没有出现在消息提示中。

$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
powershell average project windows-messages
1个回答
0
投票

我假设你的问题是关于如何创建一个

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)
© www.soinside.com 2019 - 2024. All rights reserved.