Swift: A simple rectangle struct

This entry is part 32 of 41 in the series Swift

A simple rectangle that calculates the area of a rectangle.

struct Rect{
    var width=0
    var height=0
    
    func area()->Int{
        return width*height
    }
    
    func printArea(){
        print("area = \(area())")
    }
}

let w = 10
let h = 5

var square = Rect(width: w, height: h)
square.printArea()

swift

Series Navigation<< Swift: A simple struct
Shuffle array in a class >>