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

Username:   Password: 
 RegisterRegister   
 counting words in a line
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Buck




PostPosted: Wed Jun 04, 2008 8:28 am   Post subject: counting words in a line

hello
im trying to do one of the excercises in the book

3. Write a program that reads words entered one to a line and
counts how many words have been entered before you give
the signal word "end" to stop execution of the program.
Experiment to determine what happens if you put several
words on a line as you enter them.

i have no idea how to count them in a line
Sponsor
Sponsor
Sponsor
sponsor
Vermette




PostPosted: Wed Jun 04, 2008 8:57 am   Post subject: RE:counting words in a line

hint: what separates words?
jeffgreco13




PostPosted: Wed Jun 04, 2008 9:54 am   Post subject: Re: counting words in a line

Well it looks like your question is simply asking for you to realize what happens when you have more than one word entered per line. So execute your program, which I'm sure you've figured out by now, and see what happens.

Hint: no matter how many words per line you put it will only be counted as one, without the proper adjustments.

Commas are your friend.
Tallguy




PostPosted: Thu Jun 05, 2008 10:56 am   Post subject: RE:counting words in a line

I made a program simmular to that for my compsci class
_______________________________
/*Alex van der Mout
Not the best.....But still works*/

var sentence : string (100)
var num : int
var count : int := 0

get sentence : *

loop
num := index (sentence, " ")
sentence := sentence (num + 1 .. *)
count := count + 1
exit when num = 0
end loop
put "You have " ..
put count ..
put " words in you sentence."
___________________________
*NOTE* this is not the BEST way of doing it, and it doesn't end once 'end' is entered, but still counts the words because of the spaces that separte each word
jeffgreco13




PostPosted: Thu Jun 05, 2008 10:57 am   Post subject: Re: counting words in a line

MAN, you gotta use the syntax brackets...
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: