main.swift232 chars12 lines
In this code, we create an empty array called rolls
to store the individual results of each dice roll, and set the initial sum to zero. We then use a for
loop to iterate 10 times, generating a random integer between 1 and 6 (inclusive) using the random(in:)
method. We add the result of each roll to the array and to the running total sum
, and print the current roll result and the sum so far to the console.
After the loop completes, we print out the entire array of rolls and the final sum.
gistlibby LogSnag