Hi Ralph,Ralph wrote:Hello,, Moneo!
Here is another quirk I find in QuickBASIC 4.5.
I ran the code in G-W BASIC, and got Odd. 0, ODD, odd, 0, A is odd.
I ran the code in QuickBASIC and got Odd, -1.734723E-18, EVEN, even, -1.734723E-18, A is odd.
So, the value that qb returns for 5 ^ 2 is not truly the integer 25, since the above shows that the difference is not 0.
It seems to me that your use of AND to detect odd or even would not be proper in qb, since further use of 5 ^ 2 as an integer would not be true in qb.
To truly get the exact integer 25, I find that Ted's answer of assigning a variable to it, seems to be the only way to go.
[code[CLS
IF F ^ 2 AND 1 THEN PRINT "Odd" ELSE PRINT "Even"
PRINT 5 ^ 2 - 25
IF 5 ^ 2 - 25 = 0 THEN PRINT "ODD" ELSE PRINT "EVEN"
IF INT(5 ^ 2) - 25 = 0 THE PRINT "odd" ELSE PRINT "even"
A = 5 ^ 2
IF A = 25 = 0 THEN PRINT "A is odd" ELSE PRINT "A is even"
In my solution above for testing for odd or even numbers, I specifically said "assuming that the number is an integer." Your code, without any DEFtype statement, will be working with the default type of Single.
Also, we already know that expressions with exponentiation are computed using floating point, and the result may give you an answer in floating point notation. This is especially true when you print the expression out without storing it first into a variable.
I don't understand why you often chose to use expressions with exponentiation, like 5 ^ 2 - 25, for testing code that has nothing to do with exponentiation.
My odd/even solution is based on using the AND operator, and yet of the 4 statements of yours that determine odd/even, only the first one uses the AND operator. What was your thinking here?
Regards..... Moneo