
-----------------------------------
R2D2
Fri Nov 18, 2016 9:54 pm

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! :(

-----------------------------------
Insectoid
Sun Nov 20, 2016 9:28 am

RE:Help!
-----------------------------------
What have you tried so far?

-----------------------------------
R2D2
Sun Nov 20, 2016 6:06 pm

Re: RE:Help!
-----------------------------------
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

-----------------------------------
Insectoid
Mon Nov 21, 2016 1:37 pm

RE:Help!
-----------------------------------
So you know how to calculate the length of a word, that's good. Do you know how to calculate an average?

-----------------------------------
R2D2
Wed Nov 23, 2016 9:35 am

Re: RE:Help!
-----------------------------------
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?

-----------------------------------
Insectoid
Wed Nov 23, 2016 9:52 am

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?

-----------------------------------
R2D2
Wed Nov 23, 2016 10:45 am

Re: 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?

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

-----------------------------------
Insectoid
Wed Nov 23, 2016 12:58 pm

RE:Help!
-----------------------------------
[code]sum := sum + word [/code]

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.

-----------------------------------
R2D2
Fri Nov 25, 2016 10:16 am

Re: RE:Help!
-----------------------------------



Sorry, i am still stuck can't figure it out  :?

-----------------------------------
Insectoid
Fri Nov 25, 2016 8:13 pm

RE:Help!
-----------------------------------
What part are you having trouble with?

-----------------------------------
R2D2
Mon Nov 28, 2016 9:03 am

Re: RE:Help!
-----------------------------------
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??

-----------------------------------
Insectoid
Mon Nov 28, 2016 10:18 am

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.
