Computer Science Canada Single Dimentional Array Reversal Game |
Author: | avinash336078 [ Tue Jun 09, 2009 5:57 pm ] | ||
Post subject: | Single Dimentional Array Reversal Game | ||
What is it you are trying to achieve? I need help editing a small part of this program I made but have no idea how What is the problem you are having? I need to set it up so that this program: 1. I need to set it up so that it shows the user how many tries it took to place the numbers in order from 0-9 2. I need to set it up so that the screen is cleared when a new number is entered and with the new rearranged sequence on the screen asking for another number 3. I need to set it up so that the random sequence is placed in its respective ordinal number. For example if the sequence is 7 8 5 3 6 9 0 1 3 2 set it up so that it looks like this once ran: Ordinal number : 1 2 3 4 5 6 7 8 9 10 Random number Sequence: 7 8 5 3 6 9 0 1 3 2 Please enter the range of numbers you want to reverse: Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) var range : int var Range : string var count : array 1 .. 10 of int var dup : array 1 .. 10 of int var count1, count2, count3 : int count1 := 0 count2 := 0 count3 := 0 colourback (0) colour (7) % The following is the errortrap for the program. procedure errortrap (var input : string, var num : int) loop put " " : 38 .. get input : * if strintok (input) = true and strint (input) > 1 and strint (input) <= 10 then num := strint (input) exit else put " " : 25, "Please enter a valid number. " end if end loop end errortrap % The following is the main program. randomize put " " : 21, " Here are the random numbers from 0 to 9." loop for j : 1 .. 10 count (j) := 0 dup (j) := 0 end for put " " : 26 .. delay (1000) for i : 1 .. 10 randint (count (i), 0, 9) loop for a : 1 .. i if count (a) = count (i) and a not= i then randint (count (i), 0, 9) count2 := 0 end if end for exit when count2 = 1 count2 := 1 end loop end for for k : 1 .. 10 put count (k) : 4 .. end for put " " exit end loop loop count2 := count2 + 1 put " " put " " : 21, " Please enter the range of numbers you want to reverse " errortrap (Range, range) for k : 1 .. range dup (k) := count (k) end for for decreasing l : range .. 1 loop count1 := count1 + 1 count (l) := dup (count1) exit end loop end for count1 := 0 put " " : 21 .. for i : 1 .. 10 put " ", count (i) .. end for for a : 2 .. 10 if count (a) - count (a - 1) = 1 then count3 := count3 + 1 end if end for if count3 = 10 then exit else count3 := 0 end if end loop put " The number of moves taken to arrange the numbers in order is ", count2
Please specify what version of Turing you are using <Turing for Windows 4.1> |