frequently ask ? : Computers : Programming : Languages : Bbcbasic

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

BBCBASIC: Windows: Math: Number: Sign: Operation: Change: How to change the sign of a number?

May 26th, 2006 13:36
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 26 May 2021 - 07:31 pm ------------------------
BBCBASIC: Windows: Math: Number: Sign: Operation: Change: How to 
change the sign of a number?
===
Method: Replace the given number by its negative value
This would be one of the most clear ways showing you want to change the
sign
--- cut here: begin --------------------------------------------------
xp = +1
REPEAT
 PRINT xp
 xp = -xp
UNTIL GET$ = ""
END
--- cut here: end ----------------------------------------------------
===
To generalize it
--- cut here: begin --------------------------------------------------
PRINT "please supply a number = ";
INPUT xp
REPEAT
 PRINT xp
 xp = -xp
UNTIL GET$ = ""
END
--- cut here: end ----------------------------------------------------
===
Even better, using a function, as you then explicitly tell
what you want to achieve
--- cut here: begin --------------------------------------------------
PRINT "please supply a number = ";
INPUT xp
REPEAT
 PRINT xp
 xp = FNMathGetNumberChangeSignR( xp )
UNTIL GET$ = ""
END
:
:
:
DEF FNMathGetNumberChangeSignR( xR )
= - xR
:
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
----------------------------------------------------------------------