Hi,
I am having a problem with this seemingly simple code. This is a program that I'm writing from a book. It asks the user to enter a zip code. If the zip code is already in the zip code array, it should increment the corresponding counter in another array. If it is not in the zip code array, add it to the END of the array and increment the counter. Then it displays the contents of the two arrays: the zip codes and the number of times each appeared.

Because the zip codes have to be added to the end of the array, the first for loop starts with the highest number and decends to the lowest. The problem seems to be that although the codes are entered from the last to the first element of the array, they are displayed from first to last. This causes the program to display 0's or just garbage values for the first elements of both arrays. If I change the display loops to display in reverse there is no problem. Any help would be appreciated. (BTW, cant use zips starting with 0.)
Code:
#include <stdio.h>

#define num_of_codes 5
#define num_of_counters 5

main()

{
	int zip_codes[] = {0,0,0,0,0},
		counters[] = {0,0,0,0,0},
	
		codes,						
		response=1,					
		entered_code;


	while(response)

	{

		printf("\nPlease enter a zip code: ");
		scanf("%d" , &entered_code);

		
		for(codes=num_of_codes; codes>0; --codes)
		
			if(zip_codes[codes] == entered_code)
				++counters[codes];
		
			
			else
																				
				if(zip_codes[codes] == 0)
					{
						zip_codes[codes] = entered_code;
						++counters[codes];
					}
					
					
						
		
			printf("\nwould you like to process another?(1 for yes, 0 for no): ");
			scanf("%d" , &response);

	}
			
	
	for(codes=0; codes<5; ++codes)
		printf("%7d" , zip_codes[codes]);
			
		printf("\n");
				
	for(codes=0; codes<5; ++codes)
		printf("%7d" , counters[codes]);

	    printf("\n");
				
}
If I change the last two for loops to the values of the first:
Code:
for(codes=num_of_codes; codes>0; --codes)
everything works.