![]() |
|
#1
|
|||
|
|||
Find duplicate numbers in an arrayI'm trying to write a program that has an array in a class. That array will take in random numbers then I will find the duplicate numbers and output the duplicate numbers(but only one of each dup). I'm getting an unhandled exception when I try to call the commonElement function. As it stands right now I only have the function outputting so I can see that I have the correct numbers being sorted out of the array.
CPP / C++ / C Code:
|
|||
|
#2
|
||||
|
||||
Re: array problemAt least one potential problem that I notice...
The array only has 20 elements, the loop conditions <= 20 will be problematic (will go out of bounds, common reason for an exception), those conditions should be < 20. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: array problemThere is nothing that makes me feel like a douche nozzle more than dumb-assing all over something as simple as this. So I fixed the i/j problem in the second for loop in the commonElement function, but I still am not seeing the proper output. It is skipping results and I don't know what else. I'm working on it though. Thanks for the help.
|
|
#4
|
||||
|
||||
Re: array problemCan you post the latest code change(s)?
EDIT: Also, a couple of other things: 1. The 'break' for case 3 appears to have been commented-out by mistake, which will 'fall through' to the default. 2. In the commonElement() function, the inner-loop (with 'j') is not necessary. Rather, use the loop with i, make it one less in the condition, and use it this way: CPP / C++ / C Code:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array Problem | lief480 | C++ Forum | 3 | 26-Oct-2008 10:12 |
| where is the problem and can you fix it (php) | oggie | MySQL / PHP Forum | 8 | 14-Apr-2008 16:08 |
| Getting a line error in register | oggie | MySQL / PHP Forum | 5 | 13-Apr-2008 17:16 |
| Returning a 2 dimensional Array from a function | vicky_brsh | C++ Forum | 1 | 04-Jan-2008 15:06 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 20:31 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The