Word Frequency program

I'm trying to write a program that takes input from the user, and

Page 1 of 1

3 Replies - 8173 Views - Last Post: 27 February 2009 - 03:08 PM Rate Topic: -----

#1 ieatnapalm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-February 09

Word Frequency program

Posted 27 February 2009 - 01:51 PM

#include <iostream>
#include <istream>
#include <map>
#include <ostream>
#include <string>
using namespace std;

int main()
{
	map<string, int> counts;
	string word;
	cout << "Enter all of the words to be counted, and 999 to run the count program.\n";
   
	while (cin >> word && word != " ")
	{
		  if (word == "999")
			 break;
			 
		  ++counts[word];
	}
	for (map<string, int>::iterator iter(counts.begin()); iter != counts.end(); ++iter)
		cout << iter->first << '\t' << iter->second << '\n';
	system("pause");	
}	



Is This A Good Question/Topic? 0
  • +

Replies To: Word Frequency program

#2 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Word Frequency program

Posted 27 February 2009 - 01:57 PM

"I'm trying to write a program that takes input from the user, and"

And what?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Word Frequency program

Posted 27 February 2009 - 03:00 PM

Heh, perhaps you need to layoff the napalm and try again! Put your question in the body of your message.

Extra points for using the code tags though! Good job!
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Word Frequency program

Posted 27 February 2009 - 03:08 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1