help with total words in a sentence and total amount of each letter
Author |
Message |
asianrandy
|
Posted: 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

|
|
 |
Tony

|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
asianrandy
|
Posted: 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
|
Posted: 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

|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|
|