count the number of words in a sentence?

Status
Not open for further replies.

helper_vb

Member
Joined
Oct 28, 2006
Messages
5
Programming Experience
Beginner
Word Counter
Write a program that will count the number of words in a sentence that is entered by the
user, and will keep track of the number of sentences entered. The program should run
similar to the following manner:
-------------------------------------------------------------------
Enter a sentence (press ENTER to end): I am sure I will like VB .Net
There are 8 words in your sentence.
Enter a sentence (press ENTER to end): John12+890’Lane.1SpaceFor4For.
There is 1 word in your sentence.
Enter a sentence (press ENTER to end): My favorite color is white and
there are 6 bedroom in our house. I have only 1 car.
There are 18 words in your sentence.
Enter a sentence (press ENTER to end):
You have entered 3 sentences with a total of 27 words.
Goodbye (press enter to close) ...
-------------------------------------------------------------------
((( Operation )))



The user enters a sentence (or more).


The application then displays the total number of words in that sentence, and prompt
again for another sentence.


When the user press ENTER to end, the program displays the total number of sentences
entered by the user as well as the total number of words.

(((Specifications)))



A word is one or more adjacent characters (other than spaces) that are separated by
one or more spaces.


Trim of the leading the trailing spaces of the text.


The number of words should be equal to the number of groups of spaces; that is, a
group of consecutive spaces should be counted as 1.


The program will keep recording until presses ENTER to end.



, so .. could u make it ??? :)

 
I think cjard's answer is the best one here. It's somewhat obvious that this is a home work assignment both from content and formatting of the text you've pasted.

As you'll see in many other posts everyone here is willing to help you learn, but no one want's to do the homework you've been assigned any more than you.

Take some time to begin the application, apply what you've learned so far, and then form some detailed questions that you need help on (i.e. "this works, but what about this part?") and the community here will support you and help you learn what you need.

You'll be far happier in the end to have learned how to do it rather than to have been handed the answer.
 
Thanx for your nice words and teach !!

but really .. I dont know how to do it .. and how to start do it ..

it's the problem when u have to do something u ( love ) to do it but u certainly dont know how !

our Dr. in the college really don't know how to teach ... and As I know it's become easier if some one get the start things from a teacher ... , but what should I do .. if our teacher couldn't now how to teach ... !

we complained ...
but the our request came with " this is new subject and we have no teacher for it "

but really ...
as I'm breathing ... I know ... that I can make something that I wana do in right way ! cos I'm not alone in this world !
:)
 
Hey,

As has been posted, it wouldn't help you at all (except in the very short term!) for someone to post the solution. However, I'm no stranger to very poor teaching so just to give you somewhere to start, take a look at this tutorial. It shouldn't take long to go through it and by the time you have you should know most of what you need to do your work.

http://www.developer.com/net/vb/article.php/3082491

After that, if you have specific questions post them.

Regards,

Andy
 
helper_vb, the problem looks like it could be a Console application.

Start by creating a new console application. Use the Console.Readline and .Writeline methods to (obviously) read and write text lines.

When you read a textline from user you have to check if nothing is written, because that is the end of program. Else you can split the text with String.Split method by spaces, the returned string array has got a .Length property that will tell how many words.

Your short-term target here is 15 lines of code using nothing but a few variables and the methods I have listed.
 
thanx ..

It seems that I'll withdraw from this subject .. and change my career .. from IS to MANAGEMENT inspite of getting A in MIS subjects .. but in the prog subject .. Im nothing !

its life !


:(


thanks GOd !
 
Not sounding good sir!
If you do decide to stick at it, just remember that none of it's as bad as it looks once you've got your head round the basics.
I wouldn't blame God though, I'm fairly sure he still programs in VB6.
 
Status
Not open for further replies.
Back
Top