Posted: Thu Feb 19, 2009 10:45 am Post subject: Sorting vowels and consonants
Hey, doing a new asignment that is as follows..
Quote:
/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
that there is no more input, clear the screen and redisplay the input so that the original
word is in one column, vowels are in another column and consonants are in the last
column. Save as lastname_array#5.t.*/
I got the user to enter their words and all that, but i don't know how to sort the vowels and consonants, i know i', supose to use 'index' and the 'lenght' function this is wat i haveso far...
Turing:
var counter :int:=0 var words :array1.. 9999ofstring put"Please enter text:End with the word '*'"
for i :1.. 9999 get words (i):*
counter := counter + 1 if words (i)="*"then
counter := counter - 1 endif exitwhen words (i)="*" endfor
for i :1.. counter
put yeah (i) ifindex(yeah (i),"aeiouAEIOU")not= 0then put yeah (i) endif endfor
Sponsor Sponsor
A.J
Posted: Thu Feb 19, 2009 10:56 am Post subject: Re: Sorting vowels and consonants
so, you have to output all the vowels and the consanants in the input phrase in sorted order ?
a good way of doing this is have an array that stores all the vowels and consanants already preordered.
now, everytime you get to a letter in the input phrase, make it 'checked' on the array..
then, eventually, just wlk through the array and output all the 'checked' vowels and consanants, and since you already preordered the letters, they are guarenteed to be in order.
Tallguy
Posted: Thu Feb 19, 2009 10:59 am Post subject: RE:Sorting vowels and consonants
so how would one precheck them?, thats wat i'm having problems with..
DemonWasp
Posted: Thu Feb 19, 2009 11:03 am Post subject: RE:Sorting vowels and consonants
The simplest way of doing this is to manually sort each letter in each word into vowel or consonant, then output.
Once you have your user input, inside the for-loop that goes over each word, you need another for-loop that goes over each letter of the given word. Inside this second loop, check whether that letter is a vowel or consonant and add it to the appropriate string. Once you've done that for each letter in the word, output.
This looks like (pseudocode, you'll need to convert it yourself):
code:
for each word (you have for i : 1 .. counter )
for each letter in word
if letter is a vowel then
vowels := vowels + letter
else
consonants := consonants + letter
end if
end for
output word, vowels, consonants all on one line here
end for
A.J
Posted: Thu Feb 19, 2009 11:05 am Post subject: Re: Sorting vowels and consonants
just have an array with a preordered copy of all the letters (vowels and consanants).
by 'checking', I mean having a array of boolean that all starts at 'false'....then set it to 'true'
eventually, just output all the elements in the array set to 'true'...
Tallguy
Posted: Fri Feb 20, 2009 12:11 pm Post subject: Re: Sorting vowels and consonants
Turing:
var counter :int:=0 var words :array1.. 9999ofstring put"Please enter text:End with the word '*'"
for i :1.. 9999 get words (i):*
counter := counter + 1 if words (i)="*"then
counter := counter - 1 endif exitwhen words (i)="*" endfor
for i :1.. counter
for d :1.. length(yeah (i)) ifindex(yeah (i),"aeiouAEIOU")not= 0then
consonant := consonant + yeah (i) else
vowel := vowel + yeah (i) endif endfor put yeah (i):20, vowel :20, consonant
endfor
Ok, i did wat you reconmeneded
DemonWasp wrote:
The simplest way of doing this is to manually sort each letter in each word into vowel or consonant, then output.
Once you have your user input, inside the for-loop that goes over each word, you need another for-loop that goes over each letter of the given word. Inside this second loop, check whether that letter is a vowel or consonant and add it to the appropriate string. Once you've done that for each letter in the word, output.
This looks like (pseudocode, you'll need to convert it yourself):
code:
for each word (you have for i : 1 .. counter )
for each letter in word
if letter is a vowel then
vowels := vowels + letter
else
consonants := consonants + letter
end if
end for
output word, vowels, consonants all on one line here
end for
but i still am having problems, i dunno wat it is though
DemonWasp
Posted: Fri Feb 20, 2009 1:03 pm Post subject: RE:Sorting vowels and consonants
First, you need to remember to tell us the exact error message when you post (including what line or lines it complains about). Otherwise, we have to copy-paste your code and run it.
Second, read Turing's documentation for what the index() method does. I think you'll find that:
code:
index (yeah(i),"aeiouAEIOU") not =0
doesn't actually determine whether yeah(i) is a vowel or not. It'd be easier to manually check whether yeah(i) is 'a', 'e', 'i', 'o' or 'u'.
Third, you need to check the index you've given in your assignment statements. It doesn't appear to do what you want it to do (it's using the length of string number i as an index into your array of words, which is incorrect).
DemonWasp
Posted: Fri Feb 20, 2009 1:21 pm Post subject: RE:Sorting vowels and consonants
Addendum: yeah(i) is a string, not a character. You need to test yeah (i) (d), which is character #d of word #i.
Sponsor Sponsor
Jessica359
Posted: Fri Feb 20, 2009 1:35 pm Post subject: Re: Sorting vowels and consonants
Alright so i'm posting this for alex since were in the same programming class but he does not have access to a coputer right now.
This is the code he has so far, it only displays the first vowel and then first consonant of the word.
Turing:
/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
that there is no more input, clear the screen and redisplay the input so that the original
word is in one column, vowels are in another column and consonants are in the last
column. Save as lastname_array#5.t.*/
var counter :int:=0 var words :array1.. 9999ofstring put"Please enter text:End with the word '*'"
for i :1.. 9999 get words (i):*
counter := counter + 1 if words (i)="*"then
counter := counter - 1 endif exitwhen words (i)="*" endfor
for i :1.. counter
watever := yeah (i) for d :1.. length(yeah (i)) ifindex("aeiouAEIOU", watever (d))not= 0then
vowel := vowel + watever (d) else
consonant := consonant + watever (d) endif endfor endfor
for i :1.. counter
put yeah (i):20, vowel(i):20, consonant(i) endfor
DemonWasp
Posted: Fri Feb 20, 2009 2:42 pm Post subject: RE:Sorting vowels and consonants
Your output is still incorrect. Currently, it will keep track of all the vowels and consonants for ALL of the words in a single variable for each. This isn't what your assignment asks for.
Look more carefully at the flow-of-control I outlined a few posts back. Look where the output occurs.
Secondly, you don't want to output vowel(i) or consonant(i), you want to output vowel and consonant.
Tallguy
Posted: Sun Feb 22, 2009 6:24 pm Post subject: Re: Sorting vowels and consonants
okay, so i got it 2 work, but it outputs everything from before as well as the new 'info', is there a way to 'cancel the old output', if you know wat i mean
Turing:
/*5. Input text from the user until a sentinel indicates end of input. After the user indicates
that there is no more input, clear the screen and redisplay the input so that the original
word is in one column, vowels are in another column and consonants are in the last
column. Save as lastname_array#5.t.*/ setscreen("graphics:550,450") var counter :int:=0 var words :array1.. 9999ofstring put"Please enter text:End with the word '*'"
for i :1.. 9999 get words (i):*
counter := counter + 1 if words (i)="*"then
counter := counter - 1 endif exitwhen words (i)="*" endfor
var vowel, consonant, watever :string:="" var count :int:=0
for i :1.. counter
count := count + 11 locatexy(0, 400 - count) put yeah (i)
watever := yeah (i) for d :1.. length(yeah (i)) ifindex("aeiouAEIOU", watever (d))not= 0then
vowel := vowel + watever (d) locatexy(175, 400 - count) put vowel
else
consonant := consonant + watever (d) locatexy(360, 400 - count) put consonant
endif endfor endfor
DemonWasp
Posted: Mon Feb 23, 2009 1:27 am Post subject: RE:Sorting vowels and consonants
The problem is that you keep adding to "vowel" and "consonant" without ever clearing the values of either. You can set them each to an empty string by something like this:
code:
vowel := ""
consonant := ""
Now you just need to figure out where to do that.
Tallguy
Posted: Mon Feb 23, 2009 2:04 pm Post subject: Re: Sorting vowels and consonants
Turing:
setscreen("graphics:550,450") var counter :int:=0 var words :array1.. 9999ofstring put"Please enter text:End with the word '*'"
for i :1.. 9999 get words (i):*
counter := counter + 1 if words (i)="*"then
counter := counter - 1 endif exitwhen words (i)="*" endfor
var vowel, consonant, watever :string:="" var count :int:=0
for i :1.. counter
count := count + 11 locatexy(0, 400 - count) put yeah (i)
watever := yeah (i) for d :1.. length(yeah (i)) ifindex("aeiouAEIOU", watever (d))not= 0then
vowel := vowel + watever (d) locatexy(175, 400 - count) put vowel
else
consonant := consonant + watever (d) locatexy(360, 400 - count) put consonant
endif endfor
vowel :=""
consonant :="" endfor
Okay, so it works for some words and doesn't for others, ...
Razgriz
Posted: Mon Feb 23, 2009 2:21 pm Post subject: RE:Sorting vowels and consonants
Works for me.
Kinda cool too :]
Jessica359
Posted: Mon Feb 23, 2009 2:22 pm Post subject: Re: Sorting vowels and consonants
Just to add on to Alex's question, words like "house" and "horse" when there inputed in the program together don't work because the consonants are duplicates, they cancel each other out for some reason and just don't show up?