# Amature needs help please!

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 07-10-2005
jaybo684
WOW....a lot of people seemed bummed that their school doesn't have computer programming...iwell, 'll be willing to share my class with those who are less fortunate to have programming classes over the summer....
• 07-10-2005
Dae
Quote:

Originally Posted by JoshR
You'd have to change the if to...

if charCount is equal to a space or newline or tab or EOF

Oh yah tab, if charCount is equal to space or tab. Not EOF because the while statement ends when its at the EOF.

BTW, my school only has 2 computer classes, networking and communications, and computer study, both are just basic crap. No programming classes, the person who said they have c++/java class are lucky. :rolleyes:
• 07-10-2005
Dae
Quote:

Originally Posted by dra
Not to be an ass or anything but although your code does a few interesting things, it doesn't achieve the topic creator's task which is to count words. althought you could count spaces, then add 1....

"One Two" <--- one space : 1 + 1 = 2 words. lol. But that's too much work in my opinion.

He must have editted his post, because he said that he was just giving the topic creator an idea of how to do it, how to count spaces and such will give the topic creator an idea of how to count words. Which is what your topic was like also, to give the topic creator an idea, not give him the complete program.
• 07-10-2005
JoshR
But...You have to know when the EOF has been found so you can count the last word
• 07-10-2005
Rashakil Fol
Quote:

Originally Posted by dra
althought you could count spaces, then add 1....

"One Two" <--- one space : 1 + 1 = 2 words.

Counting spaces does not work.

How many words are in this file:
Code:

`one        two          three`
• 07-10-2005
Dae
Quote:

Originally Posted by JoshR
But...You have to know when the EOF has been found so you can count the last word

Ohhh yeah you're right you would if you were counting by spaces. In that case I'd use dra's code, count strings, thats the one I was thinking of cause I was playing with that code myself, it works well and easily.
• 07-10-2005
jaybo684
dae...how do you write the code if it counts the strings?
• 07-10-2005
Dae
Quote:

Originally Posted by jaybo684
dae...how do you write the code if it counts the strings?

I dont know how I can help without giving you the program, its pretty much exactly what dra's code is:

Code:

```#include <iostream> #include <string> using namespace std; int main(){         string s;     int i = 0;     while ( cin >> s ){                     i++;     }         cout << "You entered " << i << " words."; }```
Open the file, and instead of cin.. use the file. I dont know if using a string is more efficient than using a char and counting words based on spaces/tabs/n/and eof, but it works and the code is simple.
• 07-10-2005
dra
Quote:

Originally Posted by Rashakil Fol
Counting spaces does not work.

How many words are in this file:
Code:

`one        two          three`

it was just a suggestion....

besides, assuming the sentences are properly written, as in one space between each word, and two after a sentence, he could probably get away with it.

But even then, it's too much work. Letting the library do all the work is best. lol.
• 07-10-2005
jaybo684
5.4 and 5.5 is what I have to do...

http://www.santarosa.edu/~ssarkar/ci.../cis10/a5.html
• 07-10-2005
major_small
I would just use a char array for 5.5 :D

technically, you'd be reading it in character by character ;)
• 07-10-2005
Dae
With all the "hints" given on this topic and on that actual page, theres a hints link, you should be able to figure it out. Dra's code implimented with what I said to do is 5.4 (with the addition of "asking for the filename to be opened (stored in a string)"). In 5.5 you simply do the same thing but instead of taking a string at a time from the file, take a char (as it says to do), and test if its a space, tab, end of line, or end of file, if it is then you add 1 to wordCount. In addition you could use a char array to store the output for 5.5, but thats pointless for this program as you can simple cout it 1 char at a time as it comes out.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12