### Array..tallying numbers

so i have an array of 300 numbers.
lets say like Tally [300];
i need to write a code which checks if any of the numbers of the arrays repeat it self and how many times does the number repeats it self.
so like if Tally [1] contains 33, and tally [4] and tally [50] and tally [70] all contain 33...
i will like to at the end have on the screen something like..33 came up 4 times or 33 = 4, or something like that...help please :)/> thanks in advance...
am not asking for the code to be written for me...but giving me an idea on how to go about it even in words and not in codes...but some guidance in words will be enough..thanks
You could do a loop to see weather they repeat,for example a for loop,start at Tally[0] if it contains 33 then print it on the screen and then move on to the next array and if the next array is equal to Tally[0] then print it on the screen and do that until all the arrays indices are checked.
you could build a map<int, int> mapping each value to the number of times it appears in the array (takes a single pass doing ++stats[value] for every value in the array, or simply convert the array directly into a multiset<int>, and then do a pass over the map/multiset printing the values whose counts are greater than one.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374`` ``````/* code by usandfriends */ #include #define RESET 0 main() { int howmany,i,n,j,count,counter,lowest,highest,tmp; count=0; lowest=0; highest=0; std::cout<<"How long is your list? "; std::cin>>howmany; std::cout<>tally[i]; if(lowest>=tally[i]) { lowest=tally[i]; } if(highest<=tally[i]) { highest=tally[i]; } } std::cout<tally[j-1]) {;} else { tmp=tally[j]; tally[j]=tally[j-1]; tally[j-1]=tmp; } } } for(i=0;i

DO NOT USE THIS CODE. It is merely an example. This code is: too long(not simplified enough) and takes up a ton of memory. Please use this AS AN EXAMPLE.

If anyone has any suggestions to fix my code up, please feel free to comment. ;D
Last edited on
Topic archived. No new replies allowed.