### Author Topic: Splitting 1023 into 1000,100,10 and units.  (Read 873 times)

#### djsb

• Full Member
• Posts: 111
##### Splitting 1023 into 1000,100,10 and units.
« on: April 03, 2024, 01:24:14 AM »
"Can you provide BCX BASIC code for splitting a decimal number from 0 to 1023 into individual units (1000,100,10 and units)?"
Copilot responded
"Certainly! Here’s how you can split a decimal number from 0 to 1023 into individual units in BCX BASIC:"
Code: [Select]
`DIM Number AS INTEGERDIM Thousands AS INTEGERDIM Hundreds AS INTEGERDIM Tens AS INTEGERDIM Ones AS INTEGERPRINT "Enter a number between 0 and 1023: "INPUT NumberIF Number >= 0 AND Number <= 1023 THEN  Thousands = INT(Number / 1000)  Number = Number MOD 1000  Hundreds = INT(Number / 100)  Number = Number MOD 100  Tens = INT(Number / 10)  Ones = Number MOD 10  PRINT "Thousands: "; Thousands  PRINT "Hundreds: "; Hundreds  PRINT "Tens: "; Tens  PRINT "Ones: "; OnesELSE  PRINT "Number is out of range."ENDIF`"This BCX BASIC program prompts the user to input a number. If the number is within the specified range, it calculates the thousands, hundreds, tens, and ones using integer division and the modulo operation. Then, it prints out the individual units. If the number is out of range, it informs the user accordingly. Remember to compile this code with a BCX BASIC compiler to run it on your system."

Needless to say this does not compile without errors. The error:
Quote
BCX BASIC to C/C++ Translator (c) 1999-2024 by Kevin Diggins
Version 8.0.8 (12/27/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
[Lines In: 24] [Lines Out: 509] [Statements: 22] [Time: 0.02 Sec's]
BCX translated [Split_Number.Bas] to [Split_Number.C] for a C Compiler
**************************************************************************
Pelles C is compiling [ "C:\Users\david\Desktop\SPLIT_NUMBER".c ] as a 64-bit CONSOLE application.
C:\Users\david\Desktop\SPLIT_NUMBER.c(519): error #2048: Undeclared identifier 'Numberfmod1000' (did you mean: ?).
C:\Users\david\Desktop\SPLIT_NUMBER.c(521): error #2048: Undeclared identifier 'Numberfmod100' (did you mean: ?).
C:\Users\david\Desktop\SPLIT_NUMBER.c(523): error #2048: Undeclared identifier 'Numberfmod10' (did you mean: ?).

is produced.

Any pointers as to how to correct this? Thanks.
« Last Edit: April 03, 2024, 01:26:41 AM by djsb »

#### MrBcx

• Hero Member
• Posts: 2146
##### Re: Splitting 1023 into 1000,100,10 and units.
« Reply #1 on: April 03, 2024, 09:28:51 AM »
The syntax for MOD in BCX is:

https://bcxbasiccoders.com/webhelp/html/mathfunctions.htm#mod

Code: [Select]
`DIM Number AS INTEGERDIM Thousands AS INTEGERDIM Hundreds AS INTEGERDIM Tens AS INTEGERDIM Ones AS INTEGERPRINT "Enter a number between 0 and 1023: "INPUT NumberIF Number >= 0 AND Number <= 1023 THEN    Thousands = INT(Number / 1000)    Number = MOD(Number, 1000)    ' MOD is a function in BCX    Hundreds = INT(Number / 100)    Number = MOD(Number, 100)    ' MOD is a function in BCX    Tens = INT(Number / 10)    Ones = MOD(Number, 10)    ' MOD is a function in BCX    PRINT "Thousands: "; Thousands    PRINT "Hundreds: "; Hundreds    PRINT "Tens: "; Tens    PRINT "Ones: "; OnesELSE    PRINT "Number is out of range."END IFPAUSE`

#### airr

• Full Member
• Posts: 157
##### Re: Splitting 1023 into 1000,100,10 and units.
« Reply #2 on: April 26, 2024, 05:12:01 PM »
Is this cheating?

Code: [Select]
`Dim as Integer Thousands, Hundreds, Tens, Ones, numberDim as String tmpinput "Enter a number between 0 and 1023: ", numberIf number >= 0 And number < 1024 Then    tmp = Lpad\$(str\$(number,1),4,48)    sscanf(tmp, "%1d%1d%1d%1d", &Thousands, &Hundreds, &Tens, &Ones)    Print "Thousands: ",Thousands    Print "Hundreds: ",Hundreds    Print "Tens: ",Tens    Print "Ones: ",OnesElse    Print "Number out of range."End IfPause`
AIR.

#### MrBcx

• Hero Member
• Posts: 2146
##### Re: Splitting 1023 into 1000,100,10 and units.
« Reply #3 on: April 26, 2024, 06:28:41 PM »

Is this cheating?

Yes ... The OP wanted to use artificial intelligence but you used AIR intelligence.

#### djsb

• Full Member
• Posts: 111
##### Re: Splitting 1023 into 1000,100,10 and units.
« Reply #4 on: April 26, 2024, 11:51:15 PM »
Thank you both. This what I love about BCX. You can try ideas really quickly and this forum is very helpful