Author Posts

October 22, 2015 at 2:11 pm

I emailed my Ph.D instructor, and I am still really lost on how to complete what needs to be completed. I would appreciate any help or tips.
I made a script that you give a range of number to. You then input a number as your guess. It tells you if it is above or below the correct number. You keep guessing numbers until you guess the right number. Then I coded a timer to tell me how long the game was played. The part I need help with is: how to I add the number of times played, and the shortest and longest times to a text file. another part that stumped me, is the log needs to update after each run of the script. Attached is my code so far.

#John Hartmann 10/22/2015
#a guessing game

$rand = new-object system.randon
$randomnumber = $,11)

write-host "this is a simple guessing game"
write-host "input a range of numbers between"
write-host "1 and 10, the program picks a"
write-host "random number, you will guess"
write-host "until you guess the write number"

[int]$rangestart = Read-Host "enter starting value"
[int]$rangestart = Read-Host "enter ending value"

$starttime = (get-date)

do {$a = read-host -prompt "What is your guess? "
if ($a -gt $randomnumber) {Write-Host "Too High, Guess Again!"}
elseif ($a -lt $Randomnumber) {Write-Host "Too Low, Guess Again!"}
elseif ($a -eq $randomnumber) {Write-Host "You did it!! It took you $g tries!"}
else {"You have to guess a number!!!"}
$g = $g + 1
} while ($a -ne $randomnumber)

$endtime = (get-date)
"elapsed time: $(($endtime-$starttime).totalseconds) seconds"

October 22, 2015 at 2:37 pm

Use the get-command cmdlet to see what is available to you for sending data out. Some potentially useful verbs could be send, out, export, etc.