Thread: word count problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    230

    word count problem [ solved]

    Hello,

    For a exercise I must make a programm which counts how many times a word is being inputted. It's a exercise from chapter 3 of Accelerated C++

    So i thought this will work :
    Code:
    #include <string>
    #include <vector>
    #include <iostream>
    
    using namespace std ;
    
    int main()
    {
    	// ask for and read the words to count
    	cout << "Enter all the words, "
    	        "followed by end-of-file: ";
    
    	vector<string> words;
    	vector<int> words_count ;
    	int found, place, teller=0 ;
    	string x ;
    
    	while (cin >> x)
    	{
    		for (teller ; words.begin(); words.end())
    		    if (x == words[teller] then
                     {
                         found = "1"
                         place = teller
                     }
              if found==1 then
                {
                    words_count [place]+=1 ;
                    found = 0 ;
                }
                else
                {
                    words.push_back(x);
                    words_count.push_back(1)
                }
    	}
    
    	for (teller; words.begin();words.end())
    	{
    	    cout << "Word" << words [teller] << "komt" << words_count[teller] << "voor";
    	}
    	return 0;
    }
    But I get a problem with the for loop.

    Who can help me and tell me what's wrong with this line.

    Roelof
    Last edited by roelof; 06-18-2010 at 08:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Replies: 1
    Last Post: 03-06-2005, 10:12 AM
  3. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  4. Word COM problem
    By UnclePunker in forum Windows Programming
    Replies: 6
    Last Post: 01-06-2005, 11:51 AM
  5. MS Word Problem
    By golfinguy4 in forum Tech Board
    Replies: 8
    Last Post: 06-22-2003, 01:33 AM