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

Username:   Password: 
 RegisterRegister   
 Help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
R2D2




PostPosted: 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! Sad
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Nov 20, 2016 9:28 am   Post subject: RE:Help!

What have you tried so far?
R2D2




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




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




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




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




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




PostPosted: Wed Nov 23, 2016 12:58 pm   Post subject: RE:Help!

code:
sum := sum + word


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.
Sponsor
Sponsor
Sponsor
sponsor
R2D2




PostPosted: Fri Nov 25, 2016 10:16 am   Post subject: Re: RE:Help!

Insectoid @ Wed Nov 23, 2016 12:58 pm wrote:
code:
sum := sum + word


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 Confused
Insectoid




PostPosted: Fri Nov 25, 2016 8:13 pm   Post subject: RE:Help!

What part are you having trouble with?
R2D2




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




PostPosted: 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.
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  [ 12 Posts ]
Jump to:   


Style:  
Search: