Computer Science Canada Counting vowels and the percentage. Help ASAP! |
Author: | chibitenshi_03 [ Wed Feb 11, 2004 6:22 pm ] |
Post subject: | Counting vowels and the percentage. Help ASAP! |
I have to write a program that counts the number of vowels and output the percentage of usage based on the number of vowels and of letters in general then i need to give the percentage of consonants used. |
Author: | Paul [ Wed Feb 11, 2004 6:27 pm ] |
Post subject: | |
oh, thats easy. if its only one word, then: use the length function, like length(word), that will count the number of letters in the word. then use the index function with a for loop and a counter like for a: 1..length(word) if index ("aeiouAEIOU", word) not = 0 then counter:=counter+1 end if end for the counter counts the number of vowels, then use the number of vowels divide by number of letters, for percentage, like percentageofvowels:=counter/length(word) the constanants is the number of letters minus vowels: constanants:=length(word)-counter percentageofcon:=constanants/length(word) |
Author: | chibitenshi_03 [ Wed Feb 11, 2004 6:41 pm ] |
Post subject: | |
umm it's not for one word. I have to open a text file and then count the number of vowels and upper and lower cases must be counted. After i need to output all the percentages. |
Author: | Paul [ Wed Feb 11, 2004 6:45 pm ] |
Post subject: | |
um.. txt files are not my area of expertise, but if its not one word then make a loop that adds all the strings into one variable, then count the number of spaces in that variable but using a counter: for a: 1..length(text) if index (" ", text(a)) not = 0 then spacecounter+=1 end for you can count the upper cases and lower caseswith a if statement and the ord function. then do the percentages, if you have trouble reading the text file, Im sure there's plenty of tutorial material around here addressing that. |
Author: | chibitenshi_03 [ Wed Feb 11, 2004 6:46 pm ] |
Post subject: | |
thanks for the help! ^^ |
Author: | chibitenshi_03 [ Wed Feb 11, 2004 7:07 pm ] |
Post subject: | |
This is what i have so far for the program: var word : string var text : int const vowel := "aeiouAEIOU" var count : int := 0 open : text, "NewText.txt", get loop delay (1000) exit when eof (text) get : text, word put word, " " .. for a : 1 .. length (word) exit when eof (text) if index (vowel, word (a)) not= 0 then count := count + 1 end if end for put "The number of occurances : ", count, "." end loop The problem is it reads each word and outputs the number of vowels. I want it to read the whole text then output the number of vowels. What do i change??? |
Author: | Paul [ Wed Feb 11, 2004 7:09 pm ] |
Post subject: | |
I think you have to keep getting everything and adding all the string into one string variable, THEN after that you start counting, I've never actually worked with txt files b4, but Im guessing keep adding to the string until eof. like you start out with: var text: string:="" then after you get one line and put it into a variable, lets call that line: line, then you go string:=string+line, and keep on adding untill the file is finished. the you look for it in the whole string, maybe |
Author: | chibitenshi_03 [ Wed Feb 11, 2004 7:28 pm ] |
Post subject: | |
thanks! ^^ |
Author: | shorthair [ Wed Feb 11, 2004 10:09 pm ] |
Post subject: | |
Here look at this one i made , it will show you how its all done and working , im to lazy to help http://www.compsci.ca/v2/viewtopic.php?t=2554&highlight=frequency |