| | |
integer comparison
![]() |
•
•
Join Date: Oct 2007
Posts: 60
Reputation:
Solved Threads: 0
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
Many thanks in advance
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
----------------------------------------------
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
Java Syntax (Toggle Plain Text)
if (a - b > 0) { // blah blah blah }
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.
•
•
Join Date: Oct 2007
Posts: 17
Reputation:
Solved Threads: 2
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)
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)
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
----------------------------------------------
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
![]() |
Similar Threads
- C Program help - Conway's Life - Stumped by some errors. (C)
- ISO C++ forbids comparison be (C++)
- check this code pleeeeeeeeeease (C++)
- how do i sort reords from Z-A? (in turbo C) (C++)
- String to integer to ascii (C)
- How do I create a program using an Array ? (C++)
- Converting byte value into integer and vice versa (C++)
Other Threads in the Java Forum
- Previous Thread: need help with java program.
- Next Thread: Random Numbers on button
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list loop map method methods mobile netbeans newbie nextline object pong problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows






