Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.62 KB | None | 0 0
  1. import Foundation
  2.  
  3. // Create the costants
  4. let minDiceAmount = 1
  5. let maxDiceAmount = 5
  6. let minFace = 1
  7. let maxFace = 6
  8.  
  9. // Accept and validate the user input
  10. var diceAmount: Int!
  11. while diceAmount == nil {
  12.     print("Enter the amount of dices from 1 to 5, then press Enter: ")
  13.     if let line = readLine(), let amount = Int(line) {
  14.         if amount >= minDiceAmount && amount <= maxDiceAmount {
  15.             diceAmount = amount
  16.         }
  17.     }
  18. }
  19.  
  20. // Create and show the result
  21. for dice in (minDiceAmount ... diceAmount) {
  22.     let face = Int.random(in: minFace ... maxFace)
  23.     print("Dice \(dice) value: \(face)")
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement