Computer Science Canada Sorting vowels and consonants |
Author: | Tallguy [ 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...
|
Author: | A.J [ 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. |
Author: | Tallguy [ 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.. |
Author: | DemonWasp [ 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):
|
Author: | A.J [ 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'... |
Author: | Tallguy [ Fri Feb 20, 2009 12:11 pm ] | ||||
Post subject: | Re: Sorting vowels and consonants | ||||
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):
but i still am having problems, i dunno wat it is though |
Author: | DemonWasp [ 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:
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). |
Author: | DemonWasp [ 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. |
Author: | Jessica359 [ 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.
|
Author: | DemonWasp [ 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. |
Author: | Tallguy [ 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
|
Author: | DemonWasp [ 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:
Now you just need to figure out where to do that. |
Author: | Tallguy [ Mon Feb 23, 2009 2:04 pm ] | ||
Post subject: | Re: Sorting vowels and consonants | ||
Okay, so it works for some words and doesn't for others, ... |
Author: | Razgriz [ Mon Feb 23, 2009 2:21 pm ] |
Post subject: | RE:Sorting vowels and consonants |
Works for me. Kinda cool too :] |
Author: | Jessica359 [ 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? |
Author: | DemonWasp [ Mon Feb 23, 2009 2:36 pm ] | ||||
Post subject: | RE:Sorting vowels and consonants | ||||
Alright. See up a few posts where I said you should do something like this:
You're pretty close, but your output is still incorrect. The reason that we've got the variables 'vowel' and 'consonant' is so that we can save outputting them until after we've figured out what ALL the vowels / consonants we need to list are.
|