Download Software Development
Transcript
HIGH LEVEL LANGUAGE PROGRAMMING – BASIC CONSTRUCTS For example, to produce: random numbers between 1 and 20, change it to number = Int (Rnd * 20) + 1 random numbers between 51 and 60, change it to number = Int (Rnd * 10) + 51 random even numbers between 0 and 10, change it to number = 2 * Int (Rnd * 6) Try experimenting with this line until you understand how it works. Sometimes it takes a little thought to work out exactly what numbers to put in, so that you get the right range and don’t miss out the highest or lowest number. Test your program with the following lines of code. In each case, make a note of the results, and explain what you get. line of code number = Int(Rnd * 200) + 1 results explanation number = Int(Rnd * 20) + 1 number = Int(Rnd * 100) + 2000 number = 2 * (Int(Rnd * 50) + 1) number = 2 ˆ (Int(Rnd * 8) + 1) Tasks: • Modify your program so that when you click on the button, it produces a single dice roll (a random number between 1 and 6). Hint: you won’t need a For ... Next loop. • Modify your program so that it produces a double dice roll, and displays the number on each dice and the total score. Hint: you will need to generate two random numbers every time you click the button. SOFTWARE DEVELOPMENT (INT 2, COMPUTING) 123