Letter frequency for a vector

I am trying to print out the letter frequency of a vector that the user inputs and what number that letter is in the ASCII. I am supposed to say, for example: "w" which is ASCII 119 occurs 2 times. Can anybody give me some hints about how to do this? I am just a beginner at programming so I don't know all the fancy language everyone uses, so try to dumb it down a little bit for me.
So far I have this. (I don't know how to make it colored and easy to read)
And as of this point, the user has already entered input:


void print_letter_frequency(string user_input, string user_option)
{

vector<int> my_vector;
my_vector = make_vector(user_input);
int frequency;
for(unsigned int i = 0; i < user_input.size(); i++)
{
frequency = count(my_vector.begin(), my_vector.end(), my_vector[i]);
if(frequency == 1)
{
cout << "\"" << user_input[i] << "\" which is ASCII " << my_vector[i] << " occurs 1 time." << endl;
}

else
{
cout << "\"" << user_input[i] << "\" which is ASCII " << my_vector[i] << " occurs " << frequency << " times." << endl;
//my_vector.erase(my_vector.begin());
}
}
}

vector<int> make_vector(string user_input) //changing input it to numbers
{

vector<int> my_vector;

for(unsigned int i = 0; i < user_input.size(); i++)
{
my_vector.push_back(user_input[i]); // changing text to numbers
}
return my_vector;

}

I figured out how to do the frequency but now I need to figure out how to make it erase all of those values so it doesn't print out "w which is ASCII 119 occurs 3 times" three times as the w value appears twice more.
I don't really know if that made sense. I need it to print out the first time that it shows up say 3 times in the input but then i need to delete those 3 values so it doesn't cout that message again.
Any tips?
ps the //erase I have is just to show that I need to delete those values. I don't know if the erase function is the way to do it though.
Last edited on
Topic archived. No new replies allowed.