Computer Science Canada Swap word function |
Author: | ssikmace [ Mon Apr 05, 2004 6:55 pm ] |
Post subject: | Swap word function |
I need to create a function that will swap the values for two string variables given as the paramaters for the function. It doesnt seem to hard but i just can't get one to work. |
Author: | omni [ Mon Apr 05, 2004 7:23 pm ] |
Post subject: | |
wouldn't you create a temporary variable in the procedure to hold one of the values? temp:=value1 value1:=value2 value2:=temp something like that? |
Author: | ssikmace [ Mon Apr 05, 2004 7:40 pm ] |
Post subject: | |
Thats what i tried but i couldn't get it to work. |
Author: | ssikmace [ Mon Apr 05, 2004 7:47 pm ] |
Post subject: | |
This is what i tried but it argued that the "Left side of Assignment is not a variable" function swap(word1,word2:string):string var temp:string temp:=word1 word1:=word2 word2:=temp end swap |
Author: | ssikmace [ Mon Apr 05, 2004 7:58 pm ] |
Post subject: | |
Ok ive fixed the previous problem so far but now how do i get it to have the switched words as my result, because its giving me "Function failed to give a result" function swap (var word1, word2 : string) : string var temp : string temp := word1 word1 := word2 word2 := temp end swap var word1 : string var word2 : string get word1 get word2 put swap (word1, word2) |
Author: | Tony [ Mon Apr 05, 2004 8:03 pm ] | ||
Post subject: | |||
? ![]() |
Author: | ssikmace [ Mon Apr 05, 2004 8:11 pm ] |
Post subject: | |
lol good enough for me, thx. As long as my variables remain switched. |
Author: | Tony [ Mon Apr 05, 2004 8:29 pm ] | ||
Post subject: | |||
well if you're happy with that, why not just use
![]() |