Author |
Message |
ssikmace
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
omni
![](http://www.ffonline.com/1_ff8gfx/index-pic1.jpg)
|
Posted: Mon Apr 05, 2004 7:23 pm Post subject: (No 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? |
|
|
|
|
![](images/spacer.gif) |
ssikmace
|
Posted: Mon Apr 05, 2004 7:40 pm Post subject: (No subject) |
|
|
Thats what i tried but i couldn't get it to work. |
|
|
|
|
![](images/spacer.gif) |
ssikmace
|
Posted: Mon Apr 05, 2004 7:47 pm Post subject: (No 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 |
|
|
|
|
![](images/spacer.gif) |
ssikmace
|
Posted: Mon Apr 05, 2004 7:58 pm Post subject: (No 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) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
ssikmace
|
Posted: Mon Apr 05, 2004 8:11 pm Post subject: (No subject) |
|
|
lol good enough for me, thx. As long as my variables remain switched. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|