Computer Science Canada Help! |
Author: | R2D2 [ Fri Nov 18, 2016 9:54 pm ] |
Post subject: | Help! |
Hi, How can I write a program that computes the average length of words in a text? Assume that there is no punctuation marks in the text. Programming is not my thing please help! ![]() |
Author: | Insectoid [ Sun Nov 20, 2016 9:28 am ] |
Post subject: | RE:Help! |
What have you tried so far? |
Author: | R2D2 [ Sun Nov 20, 2016 6:06 pm ] |
Post subject: | Re: RE:Help! |
Insectoid @ Sun Nov 20, 2016 9:28 am wrote: What have you tried so far?
This is what I have done var word : string loop put "Enter Word" get word put word, " has " , length (word), " letters " end loop |
Author: | Insectoid [ Mon Nov 21, 2016 1:37 pm ] |
Post subject: | RE:Help! |
So you know how to calculate the length of a word, that's good. Do you know how to calculate an average? |
Author: | R2D2 [ Wed Nov 23, 2016 9:35 am ] |
Post subject: | Re: RE:Help! |
Insectoid @ Mon Nov 21, 2016 1:37 pm wrote: So you know how to calculate the length of a word, that's good. Do you know how to calculate an average?
No, i do not. How can i calculate the average? |
Author: | Insectoid [ Wed Nov 23, 2016 9:52 am ] |
Post subject: | RE:Help! |
You calculate an average by adding all your things together and then dividing by the number of things. Does that sound familiar? You know how to length of a word already, so what's your next step? |
Author: | R2D2 [ Wed Nov 23, 2016 10:45 am ] |
Post subject: | Re: RE:Help! |
Insectoid @ Wed Nov 23, 2016 9:52 am wrote: You calculate an average by adding all your things together and then dividing by the number of things. Does that sound familiar? You know how to length of a word already, so what's your next step?
Sorry i still can't figure it out This is what i am trying, but does not work. var word : string var sum : int := 0 loop put "Enter Word" get word sum := sum + word put word, " has " , length (word), " letters " end loop |
Author: | Insectoid [ Wed Nov 23, 2016 12:58 pm ] | ||
Post subject: | RE:Help! | ||
Sum is an int. word is a string. You can't add strings to ints. This is literally no different than saying sum := sum + "banana". Does that make sense to you? How the heck do you add "banana" to sum? Remember, Turing's error messages actually mean something. They are trying to tell you what you did wrong, so reading them and try to figure out what they mean. |
Author: | R2D2 [ Fri Nov 25, 2016 10:16 am ] | ||
Post subject: | Re: RE:Help! | ||
Insectoid @ Wed Nov 23, 2016 12:58 pm wrote:
Sum is an int. word is a string. You can't add strings to ints. This is literally no different than saying sum := sum + "banana". Does that make sense to you? How the heck do you add "banana" to sum? Remember, Turing's error messages actually mean something. They are trying to tell you what you did wrong, so reading them and try to figure out what they mean. Sorry, i am still stuck can't figure it out ![]() |
Author: | Insectoid [ Fri Nov 25, 2016 8:13 pm ] |
Post subject: | RE:Help! |
What part are you having trouble with? |
Author: | R2D2 [ Mon Nov 28, 2016 9:03 am ] |
Post subject: | Re: RE:Help! |
Insectoid @ Fri Nov 25, 2016 8:13 pm wrote: What part are you having trouble with?
How can calculate the average, i know to calculate average you add up all the numbers, then divide by how many numbers there are. But how can i do this since there are no number just a word for example: Enter Word : CAT CAT has 3 letters how can calculate the average form this?? |
Author: | Insectoid [ Mon Nov 28, 2016 10:18 am ] |
Post subject: | RE:Help! |
In order to calculate the average length of the words, you need to add up all the lengths, and then divide by the number of words. |