I am trying to read in a word to a string and then output the letters, in alphabetical order, and count how many instances of that letter.

array
a 2
r 2
y 1

#include "ArrayList.h"
#include <iostream>
#include <string>

struct ItemType
{
  char letter;
  int count;
};

int main()
{
  ArrayList<ItemType> mylist;
  ItemType anItem;
  string word;

  cout << "Enter a word: "<< endl;
  cin >> word;

   sort(word.begin(), word.end()); // sorts string

  //this doesnt work
  for (int i=0; i<word.length();i++)
  {
    if (word[i] == 'a')
      {
      anItem.count += 1;
      mylist.insert(1,anItem);
      }
     if (word[i] == 'b')
     {
      anItem.count +=1;
      mylist.insert(1,anItem);
     }
  }

  ItemType someItem = mylist.getEntry(1);
  ItemType someItem = mylist.getEntry(2);

  cout << someItem.letter << someItem.count << endl;
  cout << word << endl;

return 0;
}

I know if I do this

struct ItemType
{
    char letter;
    int count
};


ArrayList<ItemType> mylist;
mylist anItem;

anItem.letter = 'a';
anItem.count = 11;
mylist.insert(1,anItem); //does this put anItem into position 1?

itemType someItem = myList.getEntry(1); //i dont understand what this does

I get a11
I just am lost with what I need to do?

So what is a ArrayList?

So, you flagged this thread as "solved". What did you do to solve it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.