# array troubles

• August 14th, 2011, 01:34 AM
mike2452
array troubles
Hi There
Im having difficulty with sorting out an element in my code.

I have an array with 6 spots that need to increment every time the user enters one of the figures.
That part i have done

I need to show what the highest and lowest scores were
Ive done that too

But now I need to attach a string to the highest and lowest. The problem is that if there are multiple spots e.g 2,2,2 for the lowest. the computer says lowest = 2 which is good but when I attach a string to match the correct array element three strings will print out. I only need it to say one, more importantly the lowest array element.

array
Assume the user knows what colour represent which number
yellow = 1, green = 2, purple = 3, white = 4, black = 5, blue = 6, red = 7

int colours[]={1,2,3,4,5,6,};
int counter[]={0,0,0,0,0,0};
e.g user enters numbers
2
2
3
3
4
4
4
5
5
5
6
6
6
7
7
7
7
I want the print out to look like this:

the lowest number was "green" with 2
the highest number was "red" with 7

Except its doing this:

The lowest number was "green" with 2
the lowest number was "purple" with 2
and so on

Any help would be awesome

Thanks
• August 14th, 2011, 04:59 AM
ha.minh.nam
Re: array troubles
Quote:

The problem is that if there are multiple spots e.g 2,2,2 for the lowest. the computer says lowest = 2 which is good but when I attach a string to match the correct array element three strings will print out. I only need it to say one, more importantly the lowest array element.
You did not tell how to attach a String to match the correct array element so I do not know what is wrong.

Why not use a pair of arrays like this:

Code :

```int colours[]={1,2,3,4,5,6,}; String colorNames[]={"yellow", "green", "purple", "white", "black", "blue"};```

immutable objects
• August 14th, 2011, 07:17 AM
Norm
Re: array troubles
Quote:

the highest number was "red" with 7
I'm confused why the print out shows 7 when the list of numbers you posted only has 4 7's in it?
• August 14th, 2011, 07:22 PM
Junky
Re: array troubles
It would help if you posted your code.