Computer Science Canada

vowel program help

Author:  dragun [ Mon Mar 08, 2004 3:08 pm ]
Post subject:  vowel program help

Hi, I was wondering if any of you can help me with this program that has been making me go crazy!

Anyways heres what i need to do:

Write a program that asks a user to enter his/her full name (first,middle, and last name) The program should inform the user of how many vowels her/his name contains. Each vowel counts as one and the "y" counts as 1/2> It should also infrom the user what percent of his/her name is made up of vowels.

Thanks for any help given.

Author:  AsianSensation [ Mon Mar 08, 2004 3:34 pm ]
Post subject: 

run a loop and use index function to search for either AEIOU. When you encountered it, add one to your counter. do an if case for Y, and add only 1/2. Percentage is just the counter divided by the total letter.

Author:  guruguru [ Mon Mar 08, 2004 6:27 pm ]
Post subject: 

Here's a simple, fast way of doing it... It only checks for lower case but you can easily change that. (I have lots of spare time lol...)

code:

var name : string
var number_vowels : real := 0
var vowel_percentage : int

put "What is your name? " ..
get name : *

for counter : 1 .. length (name)
    if name (counter) = "a" or name (counter) = "e" or name (counter) = "i" or name (counter) = "o" or name (counter) = "u" then
        number_vowels += 1
    elsif name (counter) = "y" then
        number_vowels += .5
    end if
end for

vowel_percentage := round (number_vowels / length (name) * 100)

put skip, "Your name contains ", number_vowels, " vowels."
put "That is ", vowel_percentage, "% of your name."


(Thanks Tony Wink )

Author:  Tony [ Mon Mar 08, 2004 6:51 pm ]
Post subject: 

you use
[code]
code here
[/code]
tags

Author:  dragun [ Mon Mar 08, 2004 7:28 pm ]
Post subject:  thanks

Hey thanks for all your help that seemed to work out great.. i wasn't quite sure how to do the index thing but thanks for the help

Author:  AsianSensation [ Mon Mar 08, 2004 8:58 pm ]
Post subject: 

here's another way, it's considered more "programming-ish"

instead of using all those or statements, make a string variable with value "AEIOUaeiou" and then run index each letter of the inputted word with the vowel string variable. This saves the need to put all that or statements. This is especially useful if you are checking to see if the letter of the words belong to some group.

Author:  dragun [ Tue Mar 23, 2004 3:21 pm ]
Post subject:  still confused

hey, I still can't figure out how to use the index function... Also is there a way to calcualte the charcters in the Full name without counting the spaces?

Author:  sport [ Tue Mar 23, 2004 3:43 pm ]
Post subject: 

Here is a way to count the name without spaces
code:

var fullname, alpha, alpha1 : string
alpha := "abcdefghijklmnopqrstuvwxyz"
alpha1 := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
get fullname : *
var count : int := 0
for i : 1 .. length (fullname)
    if index (alpha, fullname (i .. i)) > 0 or index (alpha, fullname (i .. i)) > 0 then
        count += 1
    end if
end for
put count

Author:  dragun [ Tue Mar 23, 2004 3:47 pm ]
Post subject:  thanks

Thanks that helped now if someone can help me understand this vowel index function

Author:  Jodo Yodo [ Tue Mar 23, 2004 5:13 pm ]
Post subject: 

When you use index, you're basically saying "Is this string inside this other string?" If it's true, index will return "1"

Thus, you can say:

if index ("a", "super")>0 then
bla bla bla

When this happens, it checks to see if "a" is in "super", and if it is, it returns "1". In this case, there are no "a"s in "super", so it only returns as 0.

Author:  Jodo Yodo [ Tue Mar 23, 2004 5:15 pm ]
Post subject: 

Therefore, you can do this:

*assume other stuff and variables done*

get words
vowels:= "AEIOUaeiou"

if index ("AEIOUaeiou", words) >0 then
end if

(Words is the stuff that the user inputs, and vowelcounter counts the number of vowels)
In this case, the phrase "AEIOUaeiou" does not necessarily have to appear in this order. In fact, if only ONE of the letters in "AEIOUaeiou" is present within variables "words", then it returns "1"

Author:  Jodo Yodo [ Tue Mar 23, 2004 5:16 pm ]
Post subject: 

index is pretty complicated, the whole string manipulation thing is tough. In fact, it has been a while since I did the string chapter, but I'm pretty sure I'm right.

I need bits. SUPER JUICY!

Author:  dragun [ Tue Mar 23, 2004 5:57 pm ]
Post subject:  so if..

so if there is say 3 "a"'s in a word the counter will output 3?
Also if thats doesn't happen how do i add a value to the index? As i stated in the first message of this thread.......?

Author:  Jodo Yodo [ Tue Mar 23, 2004 5:59 pm ]
Post subject: 

What you can do is go through each letter individually. You do this.

get word
lengthword:=length (word)

for counter:1..lengthword
if index ("AEIOUaeiou", word (counter))>0 then
wordcounter:=wordcounter+1
end if
end for

Author:  nadim [ Tue Mar 23, 2004 6:19 pm ]
Post subject:  Hey I am also doing the same program......

I think that you need need something like - 3 for the spaces

Author:  nadim [ Tue Mar 23, 2004 6:21 pm ]
Post subject:  Hey I am also doing the same program......

Hi, I took the parts from below so don't get mad...lol

var fullname, alpha, alpha1 : string
alpha := "abcdefghijklmnopqrstuvwxyz"
alpha1 := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var wordcounter:int:=0
put "Please enter your fullname,"
get fullname : *
var lengthword:=length (fullname)
put "Hello,", fullname
var count : int := 0
for i : 1 .. length (fullname)
if index (alpha, fullname (i .. i)) > 0 or index (alpha, fullname (i .. i)) > 0 then
count += 1
end if
end for
put "The number of characters in your name is," , count


for counter:1..lengthword
if index ("AEIOUaeiou", fullname (counter))>0 then
wordcounter:=wordcounter+1
end if
end for

I still can't for it to output the percent of the vowels or the number of each vowels... HELP!!! [/code]

Author:  Jodo Yodo [ Tue Mar 23, 2004 6:22 pm ]
Post subject: 

Instead of that whole second part, you could've had:

counter:=length (fullname)

That is, unless you didn't want to count the spaces.

Author:  dragun [ Tue Mar 23, 2004 6:31 pm ]
Post subject:  ok say i input...

If i input lets say <Jerry Seinfeld>
And if AEOUIaeoui each count as 1 and Yy count as 0.5
The output should state

A-0 0%
E-3 23.1%
O-0 0%
U-O 0%
Y-1 3.8%(.5/13)
I-1 7.7%

The total # of vowels = 4.5
Total Characters in Name =13
Perecent of name made up of vowels= 34.6%

Any ideas on that twist???

Author:  sport [ Tue Mar 23, 2004 6:33 pm ]
Post subject: 

Index procedure has the form

index (s , patt)

Where s is the word where you look and patt is the pattern and both of them have to be string.

Index returs an integer number and that number is the first occurs of the pattern (patt) in word (s).

Author:  nadim [ Tue Mar 23, 2004 6:34 pm ]
Post subject: 

Yeah didnt want to count the spaces lol if it was only that easy Rolling Eyes

Author:  AsianSensation [ Tue Mar 23, 2004 6:44 pm ]
Post subject: 

code:
var vowel := "AaEeIiOoUu"
var vcount : array 1 .. 11 of real
for rep : 1 .. 11
    vcount (rep) := 0
end for
var word : string
var counter := 0.0

get word : *

for rep : 1 .. length (word)
    if word (rep) not= " " then
        counter += 1
    end if
    if index (vowel, word (rep)) > 0 then
        vcount (index (vowel, word (rep))) += 1
    elsif word (rep) = "Y" or word (rep) = "y" then
        vcount (11) += 0.5
    end if
end for

for rep : 1 .. 10 by 2
    put vowel (rep), " ", (vcount (rep) + vcount (rep + 1)) * 100 / counter, "%"
end for
put "Y ", vcount (11) * 100 / counter

put counter


Twist? what twist? This sounded just like the original program you wanted.....

Author:  dragun [ Tue Mar 23, 2004 6:51 pm ]
Post subject:  lol

i left the twist out Embarassed lol although that seem to motivate you lol.... Thanks for the program although havent learned what an array is thanks again

Author:  nadim [ Tue Mar 23, 2004 7:09 pm ]
Post subject:  Umm.....

how would you put that there is 3 e's in jerry seinfeld?? everything else seems to work fine....

Author:  Paul [ Tue Mar 23, 2004 7:43 pm ]
Post subject: 

depends on if your looking for "e"'s in particular, if you are just use index to try and find e in each letter of "Jerry Seinfeld", and add it in a counter, if your not, the use AEIOUaeiou, and do some if statements that if e is found, it adds to the e counter or soemthing.

Author:  dragun [ Tue Mar 23, 2004 10:57 pm ]
Post subject:  does anybody know .....

You guys have helped alot but before i go to sleep just wanted to ask if anyone knows how to do this program without arrays and just keep it newbish as possible such as just the index and string manipulation...

Author:  Paul [ Wed Mar 24, 2004 2:37 pm ]
Post subject:  Re: vowel program help

dragun wrote:
Hi, I was wondering if any of you can help me with this program that has been making me go crazy!

Anyways heres what i need to do:

Write a program that asks a user to enter his/her full name (first,middle, and last name) The program should inform the user of how many vowels her/his name contains. Each vowel counts as one and the "y" counts as 1/2> It should also infrom the user what percent of his/her name is made up of vowels.

Thanks for any help given.

ok
code:

var name: string
var vowel, counter: real:=0
put "Put your full name: "
get name:*
for a: 1..length(name)
if index ("AEIOUaeiou", name(a)) not = 0 then
vowel+=1
end if
if index ("yY", name(a)) not =0 then
vowel+=0.5
end if
if index (" ", name(a)) not = 0 then
counter+=1
end if
end for
put "Your name has ", vowel, " vowels in it."
put (vowel/(length(name)-counter))*100, " Percent of your name is vowels."

THis shows percentage minus the spaces in the name.

Author:  Jodo Yodo [ Wed Mar 24, 2004 10:30 pm ]
Post subject: 

Here's a more literal code that isn't very efficient, but gives the percentage of vowels and the number of them, and also ignore spaces.
code:

var words : string
var acounter, ecounter, icounter, ocounter, ucounter, ycounter : int := 0
var lword : int
var vowels : int := 0
var percentage : real

get words : *
lword := length (words)

for counter : 1 .. lword
    if words (counter) = "A" or words (counter) = "a" then
        acounter += 1
    elsif words (counter) = "E" or words (counter) = "e" then
        ecounter += 1
    elsif words (counter) = "I" or words (counter) = "i" then
        icounter += 1
    elsif words (counter) = "O" or words (counter) = "o" then
        ocounter += 1
    elsif words (counter) = "U" or words (counter) = "u" then
        ucounter += 1
    elsif words (counter) = "Y" or words (counter) = "y" then
        ycounter += 1
    elsif words (counter) = " " then
        lword := lword - 1
    end if
end for

vowels := vowels + acounter + ecounter + icounter + ocounter + ucounter + (ycounter div 2)

put "There are ", vowels, " vowels in your name."

percentage := vowels * 100 div lword

put "The percentage of letters that are vowels is ", percentage, "%."


SUPER JUICY!


: