Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.98 KB | None | 0 0
  1. enum CalculationType {
  2.     case addition
  3.     case subtraction
  4.     case multiplication
  5.     case division
  6. }
  7.  
  8. func resultMathOperation(firstNumber: Int, secondNumber: Int, operation: CalculationType) -> Int {
  9.     var result: Int
  10.     switch operation {
  11.     case .addition:
  12.         result = firstNumber + secondNumber
  13.         print("Result of addition \(firstNumber) and \(secondNumber):")
  14.     case .subtraction:
  15.         result = firstNumber - secondNumber
  16.         print("Result of subtraction \(firstNumber) and \(secondNumber):")
  17.     case .multiplication:
  18.         result = firstNumber * secondNumber
  19.         print("Result of multiplication \(firstNumber) and \(secondNumber):")
  20.     case .division:
  21.          result = firstNumber / secondNumber
  22.          print("Result of division \(firstNumber) and \(secondNumber):")
  23.     }
  24.     return result
  25. }
  26.  
  27. let arithmeticAction = CalculationType.division
  28.  
  29. print(resultMathOperation(firstNumber: 18, secondNumber: 6, operation: arithmeticAction))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement