Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- // Create the costants
- let minDiceAmount = 1
- let maxDiceAmount = 5
- let minFace = 1
- let maxFace = 6
- // Accept and validate the user input
- var diceAmount: Int!
- while diceAmount == nil {
- print("Enter the amount of dices from 1 to 5, then press Enter: ")
- if let line = readLine(), let amount = Int(line) {
- if amount >= minDiceAmount && amount <= maxDiceAmount {
- diceAmount = amount
- }
- }
- }
- // Create and show the result
- for dice in (minDiceAmount ... diceAmount) {
- let face = Int.random(in: minFace ... maxFace)
- print("Dice \(dice) value: \(face)")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement