Computer Science Canada Skipping last word |
Author: | cat8864 [ Tue Nov 25, 2008 2:10 pm ] | ||
Post subject: | Skipping last word | ||
The goal os to create a program that finds the largest word in the sentence and displays it. I've managed that but it always skips the last word in the sentence even if it's the longest. Any ideas?
|
Author: | MihaiG [ Tue Nov 25, 2008 9:08 pm ] | ||
Post subject: | Re: Skipping last word | ||
hey cat8864
i just wrote that up, what i did is i would check for spaces using the index function and then get store the word from the beginning to that point in a temporary varaible, i would then delete the first part of the sentance and repeat the process, if i got two words that had the same length i compared them arithmetically (so which was is further in the dictionary type of thing), hopefully this should help somehow, i also added a space at the end of the program so when i tried to index that last word it would find the end, rember if the index cannot find the required phrase in the string it will return a value of 0, so i am assuming that will never happen till it hits the end, so if that does happen that means im done parsing the string i wont comment the code, so you can take a look at it and try to understand how it works, if you have any questions feel free to post them, note, i did not do the tallying, you already had that implmented in your code |
Author: | cat8864 [ Tue Nov 25, 2008 10:28 pm ] |
Post subject: | Re: Skipping last word |
Lets see if I've got this right: 1. the (pos - 1) finds the position of then end of the first word. 2. temp2 is the first word of the string up to but not including the space 3. temp1 is an empty string which becomes temp2 (stores the word if larger than the previous) 4. the sentence becomes the sentence - temp2 5. repeat until the position of the " " = 0 or the only thing left in the string is " " what I don't get is the first part of the if statement part: if length (temp2) = length (temp1) then if temp2 > temp1 then temp1 := sentence (1 .. (pos - 1)) end if And I still don't know what I did wrong in my code though |
Author: | MihaiG [ Wed Nov 26, 2008 1:33 am ] |
Post subject: | Re: Skipping last word |
1. yes 2. yes 3. yes 4. not really that way, but i concactenate the first part of the string inluding the space, 5. yes what that snippet of code did is if you have two words such as seven and hello, you can see they are the same length, but seven is "larger" cause the letters it uses are further up in the alphabet, just try re-writing your code, that usually can helps cause you might take a different approach |
Author: | cat8864 [ Wed Nov 26, 2008 10:52 pm ] |
Post subject: | RE:Skipping last word |
Thanks for the help! |