Here is a small script i made to enter 10 values, and then come out with the Highest of these value.....but its always returning me 9 as highest value, lets say my 10 values are 1,2,3,4,5,100,1000,9
then i get 9 as my highest value. What is wrong ?
Write-Host "Enter 10 number higher than -1:" #Output Text on the line.
$v = 0 #Variable
$vn = 0 #Variable
for ($a = 1; $a -le 10; $a++) { #For statement
$vn = Read-Host "Enter number # " $a #Output "enter value number $a" then get the value $vn from keyboard.
if ($vn -gt $v) { $v = $vn } #If $vn is higher than the value $v then i put $vn into $v
}
Write-Host "The highest value is " $v #Output "the highest value is" value $v
I i enter the value, 100,200,300,800,1000,900,768,654,543 my highest value will be 900 , i noticed that if the number dont have the same digital lenght, they gont get compared prolerly. Vry weird.
I fixed my problem by changing my first 2 varibles from $v and $nv to [int]$v and [int]$nv thx alot megamon for your answer.
then i get 9 as my highest value. What is wrong ?
Write-Host "Enter 10 number higher than -1:" #Output Text on the line.
$v = 0 #Variable
$vn = 0 #Variable
for ($a = 1; $a -le 10; $a++) { #For statement
$vn = Read-Host "Enter number # " $a #Output "enter value number $a" then get the value $vn from keyboard.
if ($vn -gt $v) { $v = $vn } #If $vn is higher than the value $v then i put $vn into $v
}
Write-Host "The highest value is " $v #Output "the highest value is" value $v
I i enter the value, 100,200,300,800,1000,900,768,654,543 my highest value will be 900 , i noticed that if the number dont have the same digital lenght, they gont get compared prolerly. Vry weird.
I fixed my problem by changing my first 2 varibles from $v and $nv to [int]$v and [int]$nv thx alot megamon for your answer.



Comment