Simple question about storing to an array

This code should be extremely simple. All it needs to do is take a char(letter) entered and then store it in an array(letterHistory) separately. As you can see, I have a simple loop that runs through ten times. These two variables need to be completely separate, the only way they effect each other is that the array stores the "history" of what the user has entered.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include<iostream>

using namespace std; 

int main()
{
	char letter;
	char letterhistory[26];
	int entries = 0; 

	do
	{
		cout << "Please enter a letter." << endl;
		cin >> letter;
		letter >> letterhistory[26]; // I know this isn't right, this is just the best my brain could come up with
	} while (entries >= 10); 

	cout << letterhistory; 


	cout << "\n\n";
	system("pause"); 
	return 0; 
}
xs[n] means "element n of the array xs".

There is no element 26 of your array, but you probably don't want to put all the letters in the same spot anyway. You have a variable handy that knows how many elements are stored in the array.

For example, suppose the array already has two elements in it. The index of the next unused element is... 2. Put the new value at element 2, then update the number of elements to three.

Hope this helps.
Topic archived. No new replies allowed.