Simple operator for returning larger of two numbers? - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Simple operator for returning larger of two numbers? (/thread-8916.html) |
Simple operator for returning larger of two numbers? - paleozord - 02-21-2006 Is there any simple mathematical operator in QBasic (or FreeBasic) that will instantly compare and return the larger of two numbers? So that if: a = 5 b = 9 Print LargerNumber (a,b) Would just automatically print 9? I know one could easily write a very small function for this purpose, but I want to know if there is an inherent function in the QB or FB syntax that accomplishes it automatically. Thanks! Simple operator for returning larger of two numbers? - Anonymous - 02-21-2006 nope, nothing intrinsic. in fb: Code: #Define larger_number(x,y) ( IIf( x < y, y, x ) ) Simple operator for returning larger of two numbers? - Dio - 02-21-2006 Code: IF a > b THEN c = a ELSE c = b Simple operator for returning larger of two numbers? - Anonymous - 02-21-2006 HAHA Simple operator for returning larger of two numbers? - anarky - 03-05-2006 You know, to me both those code snippets were useless. Code: Declare Sub LargerNumber(x,y) Just to be sure I have tested this in FreeBasic. I originally had a function and a call as follows: Code: Result=LargerNumber(x,y) ...but that gave me "0" as the output. Changing the function to a sub and changing the way I called it: Code: LargerNumber(x,y) ...and it worked this way. Of course, feel free to change things as you see fit. Enjoy. >anarky Simple operator for returning larger of two numbers? - yetifoot - 03-05-2006 iif Code: Dim As Integer a, b, c EDIT: whoops, i see chaos already did it. Simple operator for returning larger of two numbers? - Ralph - 03-06-2006 chaOs', Dio's and Yetifoot's solutions give a wrong answer for the two values equal to each other. Anarky's solution is the only complete one. Here is my proposed QuickBASIC 4.5 solution: Code: CLS Simple operator for returning larger of two numbers? - yetifoot - 03-06-2006 I don't understand. He didn't specify he needed to know if they're equal. Simple operator for returning larger of two numbers? - Ralph - 03-06-2006 No, he didn't, but he asked to know which was greater. The result when they are equal, with your code, is to report that one is greater, even when they are both equal. So, by implication, the question, 'Which of these two numbers is greater?", must be answered with "Neither, they are both equal", or some such answer, when that case exisits. Simple operator for returning larger of two numbers? - anarky - 03-06-2006 Now who's wrong? |