integer comparison

Reply

Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

integer comparison

 
0
  #1
Nov 19th, 2007
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.

Many thanks in advance
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: integer comparison

 
0
  #2
Nov 19th, 2007
And what is your question?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: integer comparison

 
0
  #3
Nov 19th, 2007
"do my homework for me", probably.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: integer comparison

 
0
  #4
Nov 19th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,444
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: integer comparison

 
0
  #5
Nov 19th, 2007
With comparison operators and subtraction.

This would normally be done through a query to a database though, not in your Java code.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: integer comparison

 
0
  #6
Nov 20th, 2007
I am afraid the requirement is only through the java code. the logic eludes me.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,383
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: integer comparison

 
0
  #7
Nov 20th, 2007
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: integer comparison

 
0
  #8
Nov 20th, 2007
  1. if (a - b > 0) {
  2. // blah blah blah
  3. }

Sheesh, how hard can it get?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 17
Reputation: uonsin is an unknown quantity at this point 
Solved Threads: 2
uonsin uonsin is offline Offline
Newbie Poster

Re: integer comparison

 
0
  #9
Nov 20th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,383
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: integer comparison

 
0
  #10
Nov 21st, 2007
Originally Posted by uonsin View Post
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC