Computer Science Canada

counting vowels in user-inputted sentence (how??)

Author:  soulgnat [ Wed Dec 17, 2003 5:26 pm ]
Post subject:  counting vowels in user-inputted sentence (how??)

Crying or Very sad Crying or Very sad i need to count the number of vowels and words in a user-inputted sentence..but im not sure how..

Newbie Smile hope you can help
I need it by tomorrow..if anyone would help please?

Author:  Dan [ Wed Dec 17, 2003 6:37 pm ]
Post subject: 

well we tend to be more helpfull when you post an atamped socrce code with your question, see we have had a problem with poleop whonting us to do there hw for them.

for this i whould recomend making an array of chars that holds vowels:

code:

var vowles: array 1..10 of char
vowles(1) := 'a'
vowles(2) := 'e'
vowles(3) := 'i'
vowles(4) := 'o'
vowles(5) := 'u'
vowles(6) := 'A'
vowles(7) := 'E'
vowles(8) := 'I'
vowles(9) := 'O'
vowles(10) := 'U'


i am not shure if you know about array's but it whould be the easetes way to do this question, for more info on them check out our tutorials

next you need to make a loop that will run as many times as there are letters in the input and one that will run as many times as there are vowles to check

length(string) will return the length of a given string

so your code will look somting like this

code:

for i: 1.. length(userInput)
     for ii: 1..10
          .....code here.....
    end for
end for


now you will need an if stament in this for loop that will uses substrings to check if any of the letters in our array is in the string.

code:

if userInput (i) = vowles (ii) then
            couter := couter + 1
end if


and there you go you will have the number of vowles in your couter varible.

Author:  JayLo [ Wed Dec 17, 2003 6:38 pm ]
Post subject: 

would index work? just a guess.


: