CS320n – Elements of Visual Programming Assignment Help Session What We Will Do Today • Illustrate a few key points on the assignment and work on the assignment Visual Programming Assignment Help Session 2 The Assignment • Simulate rolling two 6 sided dice • Allow user to input number of times to roll – numeric control – this will be input to for loop count terminal • inside for loop – need to simulate rolling dice once – need to count up how many times each result occurs – can use an array to do this Visual Programming Assignment Help Session 3 Counting Number of Rolls • One approach • One way of counting number of times each value rolled – store all results in an array – go through array and count number of 2s, then number of 3s, then number of 4s… – A reasonable function would be: how many elements of an array equal some value, but there is no LabVIEW function for this Visual Programming Assignment Help Session 4 Mapping • Another approach • A useful technique in programming • instead of using an array to hold the results of the roll, use an array to count the number of times each roll occurs • the index of the array is used to map to the result of a roll Visual Programming Assignment Help Session 5 Sample Array use result of roll as index into array Index 0 Element 0 1 0 2 1 3 3 4 7 5 8 6 7 12 40 element indicates how many time that roll has occurred. 1 two, 3 threes, 7 fours… Assume the next roll is a 4. How does array change? Visual Programming Assignment Help Session 6 Result is 4 Index 0 Element 0 1 0 2 1 3 3 4 8 5 8 6 7 12 40 Element at index 4 incremented by 1. Was 7, now is 8. Visual Programming Assignment Help Session 7 Using Mapping • To use mapping auto indexing is not useful when rolling the dice and counting the results • Need to use a shift register to pass whole array between iterations of the loop • need to use the Index Array to get old value of element, increment it (add 1), and then use the Replace Array Subset function to update the element Visual Programming Assignment Help Session 8