Skip to content

Commit

Permalink
Add dice sum
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Apr 12, 2024
1 parent ab1bd22 commit cd0874b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dice-game/src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ class Main {
rollDice(Sys.stdin()); // get input to roll the dice based on input
}

static function rollDice(input:haxe.io.Input) {
static function rollDice(input:haxe.io.Input):Void {
var numberOfDice:Int = Std.parseInt(input.readLine()); // parse input to integer
var dice:Array<Int> = []; // initialize empty array of dice
for (i in 0...numberOfDice) {
var sum:Int = 0; // initialize sum to 0
for (i in 0...numberOfDice) { // loop to entered number of dice based on input
dice[i] = Std.random(6); // add dice array to rolled die
sum += dice[i]; // add die value to sum
trace('Dice ${i + 1}: ${dice[i]}'); // print die roll value
}
trace('Sum of dice: ${sum}'); // print sum of all dice
}
}

0 comments on commit cd0874b

Please sign in to comment.