![]() |
|
#1
|
|||
|
|||
Unable to search for the nearest valueHi,
I'm having a problem on the searching for the nearest value. Here's my code, can anyone help to see what's the problem of my code? CPP / C++ / C Code:
Last edited by LuciWiz : 07-Oct-2005 at 01:19.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|||
|
#2
|
||||
|
||||
Re: Unable to search for the nearest valuehi..
Your code has no errors. it compiled and ran successfully. what compiler do you use? did your program displays the array, asks for the input and exits immediately without showing you the output? Then you should pause your program for a while to show the output. You may use getchar() to make your program wait. But there are other options.. You can get more information on pausing a program here. i think your program is too much complicated to find a number in an array. i have written a simple(i think) C code for searching a value in an array. the program is: CPP / C++ / C Code:
Paramesh |
|
#3
|
|||
|
|||
Re: Unable to search for the nearest valueHi,
I'm using GCC as my compiler. My program is correct, I'm trying to search for the nearest value and not the exact value in unsorted array. For example, if I search for value 14, the result should gave me 15 (the nearest) but now it gave me 30. Anyway, thanks for your help. Regards, |
|
#4
|
||||
|
||||
Re: Unable to search for the nearest valueI agree that the program is more complex than it needs to be. What you could do is simply run a loop like Paramesh did. Keep track of
1) the index of the current minimum 2) target is the value looking for and test for CPP / C++ / C Code:
So which value to you save if you find two values? Like if 15 and 13 are in the list? __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#5
|
||||
|
||||
Re: Unable to search for the nearest valuehi Yvonne,
i am terribly sorry that i misunderstood your program.. what mislead me was your last two printf statements.. CPP / C++ / C Code:
Bye, Paramesh |
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 |
| database search | skyloon | MySQL / PHP Forum | 6 | 04-Jun-2006 13:09 |
| Web Site Optimization - the basic things | dimos31 | Search Engine Optimization Forum | 3 | 19-Jun-2005 13:00 |
| Using meta tags help in ranking on some search engine | pcx | Search Engine Optimization Forum | 8 | 29-Mar-2005 16:42 |
| Search Engine Positioning 101 and 201 "How To" Tips... | 000 | Search Engine Optimization Forum | 0 | 29-May-2003 11:34 |
| [class] 404 search function code | jrobbio | MySQL / PHP Forum | 6 | 22-Apr-2003 10:32 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The