I am doing a homework assignment. I do not want the complete answer, just a hint. I have to load a file of names into an array, display the names, then sort the names alphabetically, display them again, then list how many names start with certain letters. I have everything done but cannot for the life of me figure out how to display how many names start with a certain letter. Here are the names Collins, Bill
Smith, Bart
Allen, Jim
Griffin, Jim
Stamey, Marty
Rose, Geri
Taylor, Terri
Johnson, Jill Allison, Jeff
Looney, Joe
Wolfe, Bill
James, Jean
Weaver, Jim
Pore, Bob
Rutherford, Greg
Javens, Renee
Harrison, Rose
Setzer, Cathy
Pike, Gordon
Holland, Beth
And here is the code I have so far. Any hints would be awesome :-)

thanks!

Code:
```#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>

using namespace std;

string name [20];

{
int i=0;
fstream in_file;
in_file.open("names.txt");
do
{
getline(in_file,name[i]);
i++;
}
while (i<=20);

}
void no_sort()
{

int i=0;

cout << "Here are the unsorted names:\n";
cout << "--------------------------\n";
do
{
cout << name[i];
cout << "\n";
i++;
}
while (i<=20);

}
void sorter()
{
string temp[20];
for(int i = 1; i <= 20; i++)
{
for (int j=0; j < (20 -1); j++)
{
if (name[j+1] < name[j])
{
temp[j] = name[j];
name[j] = name[j+1];
name[j+1] = temp[j];

}
}
}
}
void sorted()
{

int i=0;

cout << "Here are the sorted names:\n";
cout << "--------------------------\n";
do
{
cout << name[i];
cout << "\n";
i++;
}
while (i<=20);

}
void howmany()
{

}

int main ()
{
no_sort();
sorter();
sorted();
howmany();

}```

2. It's not clear what the goal is for "how many names start with a certain letter". Are you just supposed to ask for a letter and then respond with how many names start with that specific letter, or are you supposed to cycle through all possible letters and report the number of names for each letter?

If you're supposed to report the number of names for all letters, you could use a loop inside a loop that goes through every letter on the outer loop, or you could use a single loop to create a "histogram" array of integers indexed by letter, where each integer is a count of the number of names that start with the letter corresponding to the index of the "histogram" array, and then another single loop to output the results of the "histogram".

3. It is supposed to output something like
Total Names that Begin with A: 2
**************************
Allen, Jim
Allison, Jeff

And so on.

Sorry, did not mean to be vague.

Thank you!

4. Originally Posted by Fitzgibbon
It is supposed to output something like
Total Names that Begin with A: 2
**************************
Allen, Jim
Allison, Jeff

And so on.
So by "and so on", I assume you mean that you're supposed to output all the names that start with 'B', then 'C', then 'D', ... . In this case, generating a histogram would be a good approach, and you would learn how to implement a histogram.

5. I am going to look into that, thank you!

6. You've got buffer overflows everywhere:
while (i<=20);

Array indexes start from 0 ... length - 1.
I suggest you read this: SourceForge.net: Safer arrays in Cpp - cpwiki

Also, avoid global variables and more consistent indenting couldn't hurt.