Select Page

Crazy Level

Swift and Xcode Resources.

Function Code Calculation Example
Published on: February 19, 2021
Author: Frank Vernon
func calculator() {
  let a = Int(readLine()!)! //First input
  let b = Int(readLine()!)! //Second input
  
  add(n1: a, n2: b)
  subtract(n1: a, n2: b)
  multiply(n1: a, n2: b)
  divide(n1: a, n2: b)
  
}

func add(n1: Int,n2: Int) {
    
    print(n1 + n2)
    
}

add(n1: 3, n2: 4)

func subtract(n1: Int,n2: Int) {
    
    print(n1-n2)
    
}

subtract(n1: 3, n2: 4)

func multiply(n1: Int,n2: Int) {
    
    print(n1*n2)
    
}

multiply(n1: 3, n2: 4)

func divide(n1: Int,n2: Int) {
    
// Note 1 Below -
//    the below "decimalN1" and "decimalN2" are Doubles now with the "n1" and "n2" changed
    
    let decimalN1 = Double(n1)
    let decimalN2 = Double(n2)

// Note 1 Above -

    
    print(decimalN1/decimalN2)
    
}

divide(n1: 3, n2: 4)