File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,28 @@ class Main {
5
5
rollDice (Sys .stdin ()); // get input to roll the dice based on input
6
6
}
7
7
8
+ static function numberWithCommas (number : Int ): String {
9
+ var numString : String = Std .string (number );
10
+ var numLen : Int = numString .length ;
11
+ var output : String = " " ;
12
+ for (i in 0 ... numLen ) {
13
+ if ((numLen - i ) % 3 == 0 && i > 0 ) {
14
+ output + = " ," ;
15
+ }
16
+ output + = numString .charAt (i );
17
+ }
18
+ return output ;
19
+ }
20
+
8
21
static function rollDice (input : haxe.io. Input ): Void {
9
22
var numberOfDice : Int = Std .parseInt (input .readLine ()); // parse input to integer
10
23
var dice : Array <Int > = []; // initialize empty array of dice
11
24
var sum : Int = 0 ; // initialize dice sum to 0
12
25
for (i in 0 ... numberOfDice ) { // loop to entered number of dice based on input
13
26
dice [i ] = Std .random (6 ) + 1 ; // add dice array to rolled die and make dice result is between 1 to 6
14
27
sum + = dice [i ]; // add die value to sum
15
- trace (' Dice ${i + 1 }: ${dice [i ]}' ); // print die roll value
28
+ trace (' Dice ${numberWithCommas ( i + 1 ) }: ${numberWithCommas ( dice [i ]) }' ); // print die roll value
16
29
}
17
- trace (' Sum of dice: ${sum }' ); // print sum of all dice
30
+ trace (' Sum of dice: ${numberWithCommas ( sum ) }' ); // print sum of all dice
18
31
}
19
32
}
You can’t perform that action at this time.
0 commit comments