Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Count and Sum [7/8]

This program rolls the dice 15 times and counts how many times it got a 6.

After running and examining the program, add a new variable named countFives with an initial value of 0 to the beginning of the source code.

Modify the program so that it also counts how many times the number 5 was rolled, by using the variable countFives. After the loop, output the value of variable countFives.

Exercise:

Reload the original source code by pressing a key F5, or by using a key combination Ctrl-R, or by using your browser's 'Reload' button on the toolbar.

Modify the program so that it rolls two dice 15 times. It should count how many times it got doubles.

Solution

	...
	#num dice1 = rn(6);
	#num dice2 = rn(6);
	println "Dice roll: ", dice1," ",dice2;
	if dice1=dice2
	...
			

Loading...