Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 vowel program help
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nadim




PostPosted: 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]
Sponsor
Sponsor
Sponsor
sponsor
Jodo Yodo




PostPosted: Tue Mar 23, 2004 6:22 pm   Post subject: (No 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.
dragun




PostPosted: 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???
sport




PostPosted: Tue Mar 23, 2004 6:33 pm   Post subject: (No 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).
nadim




PostPosted: Tue Mar 23, 2004 6:34 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 23, 2004 6:44 pm   Post subject: (No 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.....
dragun




PostPosted: 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
nadim




PostPosted: 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....
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue Mar 23, 2004 7:43 pm   Post subject: (No 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.
dragun




PostPosted: 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...
Paul




PostPosted: 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.
Jodo Yodo




PostPosted: Wed Mar 24, 2004 10:30 pm   Post subject: (No 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!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 27 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: