## Data Type Mismatch in QBASIC

## Data Type Mismatch in QBASIC

(OP)

Hi Mikrom,

Your help appreciated please.

I keep getting a TYPE MISMATCH Error on Line 14 ( Line No 240)

Can you help please.

100 REM 6N +- 1 Test V15.3

110 DIM P1 AS LONG

115 DIM P2 AS LONG

120 DIM N1 AS LONG

125 DIM N2 AS LONG

130 INPUT “Number “; N

140 IF N <= 0 THEN GOTO 999

150 N1 = N

160 N2 = N

200 P1 = (6 * N1) -1

210 FOR N1 = 2 TO SQR(P1)

220 IF P1 MOD N1 = 0 THEN PRINT USING “################”; P1; "is Composite": GOTO 300

230 NEXT N1

240 PRINT USING “################”; P1; " is Prime"

300 P2 = (6 * N2) +1

310 FOR N2 = 2 TO SQR(P2)

320 IF P2 MOD N2 = 0 THEN PRINT USING “################”; P2; "is Composite": GOTO 130

330 NEXT N2

340 PRINT USING “################”; P2; " is Prime"

350 GOTO 130

999 END

Pervez

Your help appreciated please.

I keep getting a TYPE MISMATCH Error on Line 14 ( Line No 240)

Can you help please.

100 REM 6N +- 1 Test V15.3

110 DIM P1 AS LONG

115 DIM P2 AS LONG

120 DIM N1 AS LONG

125 DIM N2 AS LONG

130 INPUT “Number “; N

140 IF N <= 0 THEN GOTO 999

150 N1 = N

160 N2 = N

200 P1 = (6 * N1) -1

210 FOR N1 = 2 TO SQR(P1)

220 IF P1 MOD N1 = 0 THEN PRINT USING “################”; P1; "is Composite": GOTO 300

230 NEXT N1

240 PRINT USING “################”; P1; " is Prime"

300 P2 = (6 * N2) +1

310 FOR N2 = 2 TO SQR(P2)

320 IF P2 MOD N2 = 0 THEN PRINT USING “################”; P2; "is Composite": GOTO 130

330 NEXT N2

340 PRINT USING “################”; P2; " is Prime"

350 GOTO 130

999 END

Pervez

## RE: Data Type Mismatch in QBASIC

Further to my post if I use PRINT instead of PRINT USING , the code works fine.

But, PRINT USING should allow me to display the output number in detail instead of in scientific exp notation.

Try the code with N = 3, 4, 5, 6, 59 and 288 to see how it works.

Pervez

## RE: Data Type Mismatch in QBASIC

it's because using one PRINT statement like this does not work

## CODE

## CODE

## RE: Data Type Mismatch in QBASIC

## CODE

## RE: Data Type Mismatch in QBASIC

Thanx for the tip.

Code works for small numbers; I will now test for 10+ digit numbers.

One more question:

Is there a way of combining the 4 DIM statements into 1 line?

eg DIM P1, P2, N1, N2 AS LONG

Thanx

pya

## RE: Data Type Mismatch in QBASIC

## CODE

## CODE

## RE: Data Type Mismatch in QBASIC

Thanx for your help.

The Code works, but ChatGPT is not impressed!

Can this code be improved V15.3

100 REM 6N +- 1 Test V15.3

110 DIM P1, P2, N1, N2 AS _Unsigned _Integer64

120 INPUT “Number “; N

130 IF N <= 0 THEN GOTO 999

140 N1 = N

150 N2 = N

200 P1 = (6 * N1) -1

210 FOR N1 = 2 TO SQR(P1)

220 IF P1 MOD N1 = 0 THEN PRINT USING “################”; P1, : PRINT "is Composite": GOTO 300

230 NEXT N1

240 PRINT USING “################”; P1, : PRINT " is Prime"

300 P2 = (6 * N2) +1

310 FOR N2 = 2 TO SQR(P2)

320 IF P2 MOD N2 = 0 THEN PRINT USING “################”; P2, : PRINT "is Composite": GOTO 120

330 NEXT N2

340 PRINT USING “################”; P2, : PRINT " is Prime"

350 GOTO 120

999 END

The code can be improved in the following ways:

Use meaningful variable names, such as number, prime1, and prime2 instead of N, P1, and P2.

Use proper indentation and spacing to make the code more readable.

Use a function to check for prime numbers instead of duplicating the code in lines 200-240 and 300-340.

Use a do-while or while loop to repeatedly prompt the user for input instead of using GOTO statements.

Consider using a more efficient algorithm for checking prime numbers, such as the Miller-Rabin primality test.

Remove unnecessary lines of code, such as line 110 and 120, instead of using _Unsigned _Integer64, you can use just integer or long.

Add proper error handling for negative input values.

Add comments throughout the code explaining what the code is doing.

I may give up coding and go back to singing!😒

pya

## RE: Data Type Mismatch in QBASIC

yes really, you can improve your code in way suggested by ChatGPT.