Hi I am creating a house search programme. the objective of this programme is to sell houses within a range specified by the potential buyer. Now the buyer would type in the amount he is willing to spend and the houses closest to this range should be presented to him/her even if they are a long way off, so long as they are the closest.
Sorry, my question is, how do I compare the integer values (price) of the houses to a user defined integer and determine which has the closest value to the user defined integer.
Well at least give it a try. Post the code and all error/compile messages as well as what it does (not) do that you expected, once you have written something.
you migh wanna do a binary search and keep some parameters until you find the closest ones
house1: $10k
house2: $25k
house3: &50k and so on and then search through the array or binary tree depending which one you wanna use to storage your data until you get the closest price
if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:
int dif = a - b;
if (dif > 0);
or
if ((a - b) > 0)
Last edited by uonsin; Nov 20th, 2007 at 11:47 pm.
if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:
int dif = a - b;
if (dif > 0);
or
if ((a - b) > 0)
Wrong.
I'm sorry, but, take two minutes to perform a test and you can avoid making false assumptions like this.
Edit: I mean, both of your examples, of course, work, but so does the original, making your "workarounds" unnecessary (although I will often use the second myself, to make maintenance of the code, for some of the novice programmers we have here, clearer).
Last edited by masijade; Nov 21st, 2007 at 2:31 am.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.