# Thread: Need some Hints on how to figure this out.

1. ## Need some Hints on how to figure this out.

Code:
```void eMath::GetIndex()
{

for(int i=0;i<MAX_SIZE;i++)
{
if(eNumber[i]== 'I' )
Counter[0]++;
if(eNumber2[i]== 'I' )
Counter[0]++;
if(eNumber[i]== 'N' )
Counter[1]++;
if(eNumber2[i]== 'N' )
Counter[1]++;
if(eNumber[i]=='9')
Counter[2]++;
if(eNumber2[i]=='9')
Counter[2]++;
if(eNumber[i]=='L')
Counter[3]++;
if(eNumber2[i]=='L')
Counter[3]++;
if(eNumber[i]=='/')
Counter[4]++;
if(eNumber2[i]=='/')
Counter[4]++;
if(eNumber[i]=='O')
Counter[5]++;
if(eNumber2[i]=='O')
Counter[5]++;
if(eNumber[i]=='Y')
Counter[6]++;
if(eNumber2[i]=='Y')
Counter[6]++;

}

}```
So i got this huge loop going through 2 arrays eNumber and eNumber2..i then store the amount of characters from each into one counter. The reason i'm doing this it's because it's supposed to add the characters together. so example if i input "III" and "III"
the output should be "IIIIII." The only problem i'm having is getting the output done with the counter. I've made an array with all the characters
Code:
`const char EG_NUMBERS[]={'I','N','9','L','/','O','Y'};`
So now i want to integrate the counter with this array. I'm having a hard time implementing it. I need it so that EG_NUMBERS outputs IIIIII, when it counts 6 "I"s. Sorry if my grammer is bad.

EDIT:
I was thinking of something along these lines. But K<length? of the counter?
Code:
```	for(int k=0;k<;k++)
cout<<EG_NUMBERS[Counter[k]]<<endl;```

2. For loop seems like a good idea. You need the loop to run Counter times, and each loop should print out a character.

3. I can't use Counter as the Loop size.
Code:
`for(int i=0;i<Counter;i++)`
wont work because counter is an array.

4. Well, presumably you know which letter you're working on, so you would use the appropriate slot of Counter for whichever letter you're trying to print.

If you're trying to do all the letters, then you would need another for loop for your for loop to live inside.

5. Code:
```	for(int i=0;i<Counter[0];i++)
{
cout<<"I";
}
for(int j=0;j<Counter[1];j++)
{
cout<<"N";
}```
i found out that this works but it's not very efficient...

6. Originally Posted by zerlok
Code:
```	for(int i=0;i<Counter[0];i++)
{
cout<<"I";
}
for(int j=0;j<Counter[1];j++)
{
cout<<"N";
}```
i found out that this works but it's not very efficient...
By what measure?

The reason I ask is that I/O (eg writing to a stream) is "not very efficient" by many measures. Unless your values of Counter[0] and Counter[1] are very large, the optimisations you can do on the above are constrained practically.

You could move the evaluation of Counter1[0] and Counter[1] out of the loops (if the array is not declared volatile), and use preincrement or rather than post-increment. Those measures might contribute to some level of efficiency gain although, in practice, a good quality compiler will often effectively do those optimisations anyway.

If your measure of inefficiency is "using two loops, not one", then you're hosed. From a maintenance perspective it is better to use two simple but clear loops rather than one obscure one.

7. Thanks for the response. The only reason i say its not efficient is because i have to write loop 7 times. So i thought of a new way of doing it.
Code:
```	for(int i=0;i<7;i++)
for(int j=0;j<eSum[i];j++)
cout<<EG_NUMBERS[i];
cout<<endl<<endl;```
The loop is very efficient..
Code:
`EG_NUMBERS[]={'I','N','9','L','/','O','Y'}`
prints it out very nicely all in one line