我正在尝试让学生的平均分数显示在 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
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)