Question

Script #2 – Leap Year Description:  Given a year, report if it is a leap year. Purpose:...

Script #2 – Leap Year

Description:  Given a year, report if it is a leap year.

Purpose: Learn the use of if statements.

Instructions:  Complete this assignment to make sure that you know how to use if statements in Powershell.

A leap year in the Gregorian calendar occurs:

  • on every year that is evenly divisible by 4
  • except every year that is evenly divisible by 100
  • unless the year is also evenly divisible by 400
  • Write a script that prompts a user for a year. After the users enters the year, inform the user if the year is a leap year.
  • Test the script to make sure it operates correctly.
  • Save the script in a .ps1 file, this will be one of the files that you submit to D2L
  • Take a print screen to show that the script is working correctly
  • Submit the script and print screen files.

Homework Answers

Answer #1
File: leapyear.ps1
Code:

$year = read-Host -Prompt 'Enter the year'
if($year % 4 -eq 0) {
        if ($year % 100 -eq 0) {
            if($year % 400 -eq 0) {
                write-host("This is Leap Year")
            }    
            else{
                write-host("Not a leap year")
            }
        }
        else {
            write-host("This is a leap year")
        }
    }    
else {
    write-host("Not a leap Year")
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Instructions PowerShell Assignment #1 Objective: Learn basic Powershell scripting in Windows Setup: A Windows computer with...
Instructions PowerShell Assignment #1 Objective: Learn basic Powershell scripting in Windows Setup: A Windows computer with the latest Powershell environment installed Script #1 – Hello World! Description:  The classical introductory exercise: Just say "Hello, World!". Purpose: A "Hello, World!" program is traditionally used to introduce novice programmers to a programming language. It is also to make sure that the interpreter is installed correctly, and that the user understands how to use it. Instructions:  Complete this assignment to make sure that you know...
3.21 LAB C++ Code: Leap Year A year in the modern Gregorian Calendar consists of 365...
3.21 LAB C++ Code: Leap Year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
The Business Case for Agility “The battle is not always to the strongest, nor the race...
The Business Case for Agility “The battle is not always to the strongest, nor the race to the swiftest, but that’s the way to bet ’em!”  —C. Morgan Cofer In This Chapter This chapter discusses the business case for Agility, presenting six benefits for teams and the enterprise. It also describes a financial model that shows why incremental development works. Takeaways Agility is not just about the team. There are product-management, project-management, and technical issues beyond the team’s control. Lean-Agile provides...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT