Last Updated: August 18, 2021
·
180
· tallemd

Powershell Math Facts

$Start = Get-Date
$clist = @{}
$dlist = @{}
$opstr = "+"
$correct = 0
$questioncount = 90
$opstr = Read-Host "Math Operator?"
if ($opstr -eq "/" -and $questioncount -gt 90)
{
$questioncount -eq 90
}
elseif($questioncount -gt 100)
{
$questioncount -eq 100
}
for ($i = 0; $i -lt $questioncount;$i++)
{
do{
if ($opstr -eq "/" )
{
$a = Get-Random -Maximum 10 -Minimum 1
$b = Get-Random -Maximum 10 -Minimum 0
}
else
{
$a = Get-Random -Maximum 10 -Minimum 0
$b = Get-Random -Maximum 10 -Minimum 0
}
$c = $a10+$b
}until(!$clist.ContainsKey($c))
$clist.Add($c,$i)
$dlist.Add($i,$c)
}
Write-Host "Please Answer"
for ($i = 0; $i -lt $questioncount;$i++)
{
#Write-Host "$([Math]::Floor($dlist.Item($i) / 10)) $opstr $($dlist.Item($i) % 10) ="
if($opstr -eq "+")
{
$answer = Read-Host "$([Math]::Floor($dlist.Item($i) / 10)) $opstr $($dlist.Item($i) % 10) ="
}
elseif($opstr -eq "-")
{
$answer = Read-Host "$([Math]::Floor($dlist.Item($i) / 10) + $dlist.Item($i) % 10) $opstr $([Math]::Floor($dlist.Item($i) / 10)) ="
}
elseif($opstr -eq "
")
{
$answer = Read-Host "$([Math]::Floor($dlist.Item($i) / 10)) $opstr $($dlist.Item($i) % 10) ="
}
elseif($opstr -eq "/" )
{
$answer = Read-Host "$([Math]::Floor($dlist.Item($i) / 10) ( $dlist.Item($i) % 10)) $opstr $([Math]::Floor($dlist.Item($i) / 10)) ="
}
if (($opstr -eq "+") -and ([Math]::Floor($dlist.Item($i) / 10) + $dlist.Item($i) % 10 -eq $answer))
{
Write-host "Correct"
$correct ++
}
elseif (($opstr -eq "-") -and ($dlist.Item($i) % 10 -eq $answer))
{
Write-host "Correct"
$correct ++
}
elseif (($opstr -eq "
") -and ([Math]::Floor($dlist.Item($i) / 10) * ($dlist.Item($i) % 10) -eq $answer))
{
Write-host "Correct"
$correct ++
}
elseif (($opstr -eq "/") -and ($dlist.Item($i) % 10 -eq $answer))
{
Write-host "Correct"
$correct ++
}
}

$Elapsed = ((Get-Date) - $Start)
if($Elapsed.Minutes -eq 0)
{
Write-Host ("Finished in " + $Elapsed.Seconds + " Sec")
}
else
{
Write-Host ("Finished in " + $Elapsed.Minutes + " Min")
}
Write-Host "Percent correct $(100 * $correct / $questioncount) %"