array and frequency

Oct 30, 2009 at 4:58am
I have come up with this code to print out a column of letters and another column of their frequencies entered but my code isn't working. Any suggestions?
char letters;
int letcount;
int total;
int array[52][2]= {a || A, b || B, c || C, d || D, e || E, f || F, g || G, h || H, i || I,
j || J, k || K, l || L, m || M, n || N, o || O, p || P, q || Q, r || R,
s || S, t || T, u || U, v || V, w || W, x || X, y || Y, z || Z};

do
{
cout << "Please print a series of letters followed by a '-' symbol" << endl;
cin << letters;

for (int i = 0; i < letters; i++)
for (int j =0; j < letcount; j++)
array [i][j]= letcount/total;
cout << array << endl;
} while (letters |= -)
Oct 30, 2009 at 12:02pm
Most of the above is totally wrong.

 
char letters;


letters is a variable that can hold exactly one character. You want it to hold several (a string), I think.
Are you supposed to allow the user to enter a string following by ENTER, or 1 character followed by
ENTER, followed by 1 character followed by ENTER, etc?

1
2
3
int array[52][2]= {a || A, b || B, c || C, d || D, e || E, f || F, g || G, h || H, i || I,
j || J, k || K, l || L, m || M, n || N, o || O, p || P, q || Q, r || R,
s || S, t || T, u || U, v || V, w || W, x || X, y || Y, z || Z};


This is total gibberish. I assume you want to differentiate between lowercase and uppercase?
If so, forget the 2D array and make it 1D.

You use letcount uninitialized.

 
while( letters |= -)


What is that supposed to mean?
Oct 30, 2009 at 9:13pm
I don't know what it is suppose to mean. I have never made an array before. I need the user to enter a series of letters and then output their frequency. If mine is 'gibberish' how do I imply that they are allowed to use both upper and lowercase?
Oct 31, 2009 at 5:53am
One way of looking at this is:
1. I think you need to do more work on your algorithm
2. Keep it simple.... only accept either upper or lower case but not both.
3. Use a one dimensional array (which is what a two dimensional array is).
4. So now you have a char array[] initialized with one case of the alphabet.
5. Now initialize a double array1[] with the frequencies corresponding with the letters.
6.Using a loop print the first item of each array separated by a space (" ") or tab(\t).
7. Repeat for the remainder of alphabet and frequencies.
You may be able to get to where you want be from here.....maybe, because your objective
changed from your original post to your next post.
hth`s
Topic archived. No new replies allowed.