Computer Science Canada I really need help with arrays! |
Author: | Jina [ Mon Jun 06, 2005 5:07 pm ] |
Post subject: | I really need help with arrays! |
hi it's me again. I do not know how to do the swapping in my program. I am having trouble swapping numbers for the number the user inputs. This is my modified prog. Remember, my program has to look like this: it has to display 0,1,2,3,4,5,6,7,8,9 in random order. After that , the user selects a number from 1 to 10 for that many nos. to be reversed. eg- random order 6,5,3,2,1,7,8,0,9 user inputs 4 order becomes 2,3,5,6,1,7,8,0,9 user has to keep inputting till the order becomes 0,1,2,3,4,5,6,7,8,9 then program has to count how many times it entered a number to get the series in order i did the for loop at the end but it does not work. The user has to keep inputting till the order is numerical and then it has to exit and show how many times he/she inputted no. var number : array 0 .. 9 of int var rand1, rand2,temp,n,counter : int var letter : string for i : 0 .. 9 number(i) := i end for for i : 0 .. 9 rand1 := Rand.Int (0, 9) rand2 := Rand.Int (0, 9) temp := number (rand1) number(rand1) := number (rand2) number(rand2) := temp end for locate (3,20) put " The Reversal Game" locate (4,20) put "------------------" locate (6,10) put " You have to reverse the list of random numbers into numerical order" locate (7,15) put " In order to do this, you must enter a no. between 1 and 10" locate (9,20) put " This is the random numbers list: " put " " for i : 0..9 put number(i):5.. end for procedure error put " " put " " : 8, "The value you entered is either a letter, a symbol or more than 10." put " " : 15, "Please re-enter a number from 1 to 10." end error locate (13,20) put "Please enter a number between 1 and 10: ".. counter := 0 loop counter := counter + 1 loop put skip get letter:* if letter >= "0" and letter <= "9" then exit elsif counter = 1 and letter = "y" then error elsif letter = "y" then exit elsif letter >= "A" and letter <= "z" then error else error end if end loop n:= strint(letter) put " " put n for decreasing i : n-1 .. 0 put number(i) : 5 .. end for for i : n .. 9 put number (i) : 5 .. end for end loop |
Author: | Tony [ Tue Jun 07, 2005 10:43 am ] |
Post subject: | |
haven't you posted this twice already? http://www.compsci.ca/v2/viewtopic.php?p=87188&highlight=#87188 http://www.compsci.ca/v2/viewtopic.php?p=87222&highlight=#87222 ![]() |