Computer Science Canada counting words in a line |
Author: | Buck [ 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 |
Author: | Vermette [ Wed Jun 04, 2008 8:57 am ] |
Post subject: | RE:counting words in a line |
hint: what separates words? |
Author: | jeffgreco13 [ 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. |
Author: | Tallguy [ 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 |
Author: | jeffgreco13 [ Thu Jun 05, 2008 10:57 am ] |
Post subject: | Re: counting words in a line |
MAN, you gotta use the syntax brackets... |