# Thread: Using an array, problem

1. I misunderstood my assignment earlier. I now understand for the part with :

The smallest digit: 0
Digit 1 can be found in integer number(s): 3

The largest digit: 9
Digit 9 can be found in integer number(s): 1, 3

that the code was supposed to extract the largest and smallest digit. I did that in my code now:

Code:
```for(i = 0; i < count; i ++){
temp = numbers[i];
while (temp!= 0){

if (temp < 0) {
temp = -temp;
}
numExtract = temp % 10;
temp /= 10;

if( numExtract > largeDigit ){
largeDigit = numExtract;

}
if( numExtract < smallDigit ){
smallDigit = numExtract;
}

}

}
cout << "\n";
cout << "The smallest digit: " << smallDigit << endl;
cout << "The largest digit: " << largeDigit << endl;```
The only thing I need to do now is print out which lines have the smallDigit and largeDigit on them.

Can anyone please help me? I'm stuck and I don't know what to do. How do I find what line (index) smallDigit and largeDigit are on?? I will appreciate ANY help.

2. Introduce two variables in the start of your program....
Code:
```int index_Lower=0;
int index_Larger=0;```
inside if's(), assign the value of i to these and you will get your answer....
Print the value of these two variables in the end....
Good luck...

3. Again, don't hand out solutions to the logic problems.

4. I just provided him with algo and not the code...
Anyways, i don't think that this simple solution is that tough for him/her to think.... May be he/she is in wrong direction so that was just to put him/her in the right direction....

5. Introduce two variables in the start of your program....
Code:
int index_Lower=0;
int index_Larger=0;
inside if's(), assign the value of i to these and you will get your answer....
Print the value of these two variables in the end....
Good luck...
Thanks, I found that out, but can I still apply this if the number is printed out on multiple indexes?

6. I'm pretty sure that part of the homework involves two separate arrays.

7. Do you think using a pointer would help in this situation?

8. *shrug* Notice how a digit can appear in more than one number in the list. That means in order to display all the places such a digit occurs in the list, you may also need to efficiently store that information. Pointers don't really mean anything here, unless they point to dynamic allocations or something.

9. I don't get how it can print multiple indexes that smallDigit and largeDigit are on, with one int.

This is my code:
Code:
```int numbers[10];
int count;
int smallDigit = 9;
int largeDigit = 0;

cout << "\tHow many integers? ";
cin >> count;
cout << "\n";

int i;
int numExtract;
int temp;
int indexSmall;
int indexLarge;

for(i = 0; i < count; i ++){
cout << "\t\tEnter integer #" << i + 1 << " : ";
cin >> numbers[i];

}

for(i = 0; i < count; i ++){

temp = numbers[i];

while (temp!= 0){
cout << i << endl;
if (temp < 0) {
temp = -temp;
}
numExtract = temp % 10;
temp /= 10;

if( numExtract > largeDigit ){
largeDigit = numExtract;
indexLarge = i + 1;
}
if( numExtract < smallDigit ){
smallDigit = numExtract;
indexSmall = i + 1;

}

}

}
cout << "\n";
cout << "The smallest digit: " << smallDigit << endl;
cout << "Digit " << smallDigit << " can be found in integer number(s): " << indexSmall << endl;
cout << "The largest digit: " << largeDigit << endl;
cout << "Digit " << largeDigit << " can be found in integer number(s): " << indexLarge << endl;```

10. Code:
```int numbers[10];
int count;
int smallDigit = 9;
int largeDigit = 0;

cout << "\tHow many integers? ";
cin >> count;
cout << "\n";

int i;
int numExtract;
int temp;
int indexSmall;
int indexLarge;

for(i = 0; i < count; i ++){
cout << "\t\tEnter integer #" << i + 1 << " : ";
cin >> numbers[i];

}

for(i = 0; i < count; i ++){

temp = numbers[i];

while (temp!= 0){
cout << i << endl;
if (temp < 0) {
temp = -temp;
}
numExtract = temp % 10;
temp /= 10;

if( numExtract > largeDigit ){
largeDigit = numExtract;
indexLarge = i + 1;
}
if( numExtract < smallDigit ){
smallDigit = numExtract;
indexSmall = i + 1;

}

}
cout << "\n";
cout << "The smallest digit: " << smallDigit << endl;
cout << "Digit " << smallDigit << " can be found in integer number(s): " << indexSmall << endl;
cout << "The largest digit: " << largeDigit << endl;
cout << "Digit " << largeDigit << " can be found in integer number(s): " << indexLarge << endl;

}```
Try this.....

This'll print smallest and largest digit and their indexes each time it completes comparisons with the inner loop.....
Now, you can think to make it much better....