Okay, important update! After racking my head for a bit, and then - TopicsExpress



          

Okay, important update! After racking my head for a bit, and then getting some much needed assistance from my mentor at Thinkful, I was able to get my dice rolling function to work! I was just barely off in my code... just a little thing I had to remember, but now that I ran into the issue this way, it is something Ill never forget. To me, that is the best kind of mistake you make, because then you understand exactly how something works. Anyway, this function allows you to set a number of sides for a die, and then the number of times it is rolled. It then prints the result. For the purposes of the Xcode playground, I also print the value of the die each time it is rolled as well just so I have a way to track it. Anyway, feel free to play with the function and if you think of fun ways to use it, let me know! /*********START CODE*************/ import UIKit func rollDice(sides: UInt32, rolls: Int) ->Int{ // dice rolling function var total = 0 // sets face total to zero for var roll = 0; roll < rolls; ++roll { // rolls dice until finished var thisRoll = Int (arc4random() % sides) + 1 println(thisRoll)// prints the current roll total = total + thisRoll // adds the current roll to the total } println(total) // prints total before setting finTotal to total return total // supposed to return the final total } let finTotal = rollDice(6, 3) // calls roll dice function for a 6 sided die rolled 3 times println(finTotal) // prints result
Posted on: Tue, 25 Nov 2014 02:37:13 +0000

Trending Topics



Recently Viewed Topics




© 2015