[SOLVED] Function with multiple parameters in swift

Issue

I need to define and call a function called areaOfRectangle that takes two Int parameters, length, and width, and prints the result of length * width. I actually got result with length * width but it is telling me to make sure I’m defining a function with the correct name and parameters. The answer below will print length * width which is right but the steps are not what it should be.

func areaOfRectangle(length: Int, width: Int) {

    print(“length * width”)

}

areaOfRectangle(length: 0, width: 0)

Solution

You have defined the function correctly but made a small mistake in the front statement as it will always print length * width in the output console as its a string not the operator or operands. Here is the solution

func areaOfRectangle(length: Int, width: Int) {

    print("\(length * width)")

}

areaOfRectangle(length: 0, width: 0)

just added ‘\'() in the print statement

Answered By – Parth Dhorda

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.