I had a problem about string
Author |
Message |
at20092009
|
Posted: Fri Nov 16, 2012 4:37 pm Post subject: I had a problem about string |
|
|
var cha : string
var a, b, c, d := ""
put "Enter a series of characters: "
const vowels := "aeiou"
const word1 := "abcdefghijklmnopqrstuvwxyz"
const word2 := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
loop
get cha
put ""
for i : 1 .. length (cha)
if index (vowels, cha (i)) = 0 and index (word1, cha (i)) not= 0 or index (word2, cha (i)) not= 0 then
a := a + cha (i)
put "consonant - ", a ..
put ""
elsif index (vowels, cha (i)) not= 0 then
b := b + cha (i)
put "vowel - ", b ..
put ""
elsif strintok (cha (i)) then
c := c + cha (i)
put "number - ", c ..
put ""
else
d := d + cha (i)
put "any other character - ", d ..
put ""
end if
end for
end loop
This is my program, but it is different from the sample of the question.
The example is, if I type "asdfert456u2~1?",
it will show
numbers - 45621
vowels - aeu
consonants - sdfrt
any other character - ~? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Fri Nov 16, 2012 5:06 pm Post subject: RE:I had a problem about string |
|
|
Your program is going to output "consonants - " every time it finds a consonante. You only want it to print once, don't you? How do you think you would fix that? Same with all your other categories, to be honest. |
|
|
|
|
|
at20092009
|
Posted: Fri Nov 16, 2012 5:21 pm Post subject: RE:I had a problem about string |
|
|
yea, i just want to show consonante once, I tried to use " .. " to fix it, but it didn't work. |
|
|
|
|
|
at20092009
|
Posted: Fri Nov 16, 2012 5:28 pm Post subject: RE:I had a problem about string |
|
|
still, i can't fix it |
|
|
|
|
|
Insectoid
|
Posted: Fri Nov 16, 2012 5:37 pm Post subject: RE:I had a problem about string |
|
|
Do you know why it's printing more than once? |
|
|
|
|
|
at20092009
|
Posted: Fri Nov 16, 2012 7:02 pm Post subject: RE:I had a problem about string |
|
|
Cause it is in the loop, so it will repeat putting the consonante, but there's no way to move this put command away from the if part, that won't work. |
|
|
|
|
|
Insectoid
|
Posted: Sat Nov 17, 2012 12:06 am Post subject: RE:I had a problem about string |
|
|
Yes, that's why, and yes, there is a way. You'll need a few extra variables but your code really won't even change much. |
|
|
|
|
|
at20092009
|
Posted: Sat Nov 17, 2012 9:31 am Post subject: RE:I had a problem about string |
|
|
extra variables?! OK, I'll try it! Thx! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|