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

Username:   Password: 
 RegisterRegister   
 help with total words in a sentence and total amount of each letter
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asianrandy




PostPosted: Wed Dec 03, 2008 1:03 pm   Post subject: help with total words in a sentence and total amount of each letter

help with total words in a sentence and total amount of each letter. lm closed to finising this assignment.

code:

var sentence : string
put "Enter a sentence"
get sentence : *
put sentence, " has ", length (sentence), "letters" % total letters in the entire sentence
for i : 1 .. length (sentence) % the longest word you can write in the sentences.
put " total words in the sentence"
put "total amount of each letter"
end for
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Dec 03, 2008 2:22 pm   Post subject: RE:help with total words in a sentence and total amount of each letter

length(sentence) would count the number the characters (including spaces and punctuation!), not letters.

You might find the index() function to be useful.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
asianrandy




PostPosted: Thu Dec 04, 2008 8:09 am   Post subject: RE:help with total words in a sentence and total amount of each letter

do i change length to count and make another line for length(sentence).
asianrandy




PostPosted: Fri Dec 05, 2008 4:09 pm   Post subject: RE:help with total words in a sentence and total amount of each letter

i got the letters of the alphabets and i don't know the code to put it, to find the total words in a sentence and total amount of each letter.
code:

var word : string
put "Enter a sentence"
get word : *
put word, " has ", length (word), " including spaces and punctuation! " % total letters in the entire sentence
var alpha := "ABCDEFGHIJKLMNOPQRSTUVWYZ......abcdefghijklmnopqrstuvwyz"
for rep : 1 .. length (word)
    if index (alpha, word(rep)) not= 0 then
    end if
end for
Tony




PostPosted: Fri Dec 05, 2008 4:36 pm   Post subject: RE:help with total words in a sentence and total amount of each letter

code:

var alpha := "ABCDEFGHIJKLMNOPQRSTUVWYZ......abcdefghijklmnopqrstuvwyz"

That would count periods as letters.

Also
code:

if index (alpha, word(rep)) not= 0 then
end if

You are not doing anything if the condition matches, although you've got the right idea. You just need a counter.

As for the number of words in a sentence -- if it's a fair assumption that words are separated by a single space, then maybe you can count the number of spaces to figure out how many words they separate.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: