dimanche 1 mai 2016

Powershell - Nested if Statement not working

I am trying to write the code for finding a leap year. However, there seems to be something wrong with the nested if and else format. Please suggest.

[int]$x = Read-Host -Prompt 'Input a year : ';

if ($x % 4 -eq 0) {
        Write-Host $x 'is a leap year';
    if ($x % 100 -eq 0){
        Write-Host $x 'is a leap year';
        if ($x % 400 -eq 0){
        Write-Host $x 'is a leap year';
        else {
            Write-Host $x 'is not a leap year';
            }
        }

    else {
            Write-Host $x 'is not a leap year';
        }
    }
else {
        Write-Host $x 'is not a leap year';
    }

}

Aucun commentaire:

Enregistrer un commentaire