Skip to content

Instantly share code, notes, and snippets.

@Pasanpr
Created November 28, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pasanpr/97adbd2b67c5de1692b30cc31a1aa0ec to your computer and use it in GitHub Desktop.
Save Pasanpr/97adbd2b67c5de1692b30cc31a1aa0ec to your computer and use it in GitHub Desktop.
Code snippet for Coin enum
enum Coin: Double {
case penny = 0.01
case nickel = 0.05
case dime = 0.1
case quarter = 0.25
}
let coins: [Coin] = [.penny, .nickel, .dime, .dime, .quarter, .quarter, .quarter]
func sum(having coins: [Coin]) -> Double {
var total: Double = 0
for coin in coins {
switch coin {
case .penny: total += 0.01
case .nickel: total += 0.05
case .dime: total += 0.1
case .quarter: total += 0.25
}
}
return total
}
sum(having: coins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment