basic calculation

  amstrad 11:12 15 Nov 2012

In basic, is there a check to see that the result of a calculation is a whole number and do something else if not?

  BT 13:01 15 Nov 2012

My BASIC is a bit rusty but the term for a whole number is INT (Integer) and you would then need to write an IF THEN routine to do your check.

Sorry I can't be a bit more specific as I'm a bit rusty but I'm sure someone else will come in with a neat solution.

  csqwared 19:33 15 Nov 2012

I think the 'MOD' function will do that for you e.g.

If MOD(number)=0

Then something

Else something else

End if

Where MOD checks to see if there is a remainder, in the instance above, no.

Long time since I did Basic.

  csqwared 19:52 15 Nov 2012

Just had a quick look on t'internet and the first line should probably be

If (n MOD 1)=0

where n is the number you are checking.

Try both.

  amstrad 08:30 16 Nov 2012

Thanks for the info. I'm not sure if the ZX 81 supports ( MOD ) we'll find out

  Terry Brown 10:17 18 Nov 2012

I did not know anyone was still using Clive's ZX81, what do you do on it.

If you need an emulator or more zx81 software, have a look at link.


enter link description here

1:;ylt=A0geu8UEtahQ2n4A0pLBQx.?ei=UTF-8&fr=ush1-finance&p=zx81%20emulator&SpellState=&fr2=sp-qrw-corr-top/ "ZX81"

  Terry Brown 10:19 18 Nov 2012;ylt=A0geu8UEtahQ2n4A0pLBQx.?ei=UTF-8&fr=ush1-finance&p=zx81+emulator&SpellState=&fr2=sp-qrw-corr-top

Link did not work, try again


  Fermat's Theorem 21:10 23 Nov 2012

I know this has been ticked as resolved, but the handiest way of checking whether a number is, and ensuring that it is, a whole number in Basic is: if x<>int(x) then x=int(x). Depending on which Basic you're using, you may have to insert appropriate quotation marks or parenthesis around int(x). Hope this is of some use to you. :-)

  csqwared 18:58 24 Nov 2012

Fermat's Theorem

Not sure that's what amstrad had in mind. Does that not alter the value of the original number? e.g.

if 1.766<>int(1.766) then 1.766=int(1.766) i.e. 1

Reading the original post I understood just a check for integer was required, if not integer do something else.

  Fermat's Theorem 20:57 24 Nov 2012

Of course , you are correct. I thought he was tying to force the calculation to be an integer if it wasn't one already. The first half of the statement still holds true though - if x<>int(x) then ..... whatever he wants to do - goto,gosub, print, stop, end etc. I'm fascinated that he's still using a ZX 81 - I started with the Spectrum way back when!

  amstrad 12:36 28 Nov 2012

Thanks guys for the interest. I am building a magnet motor and using the ZX81 to do the calculations. It makes a brillient programable calculator which will print out the calculations and results and save all to tape. Unfortunately it died on me. Now looking for a bootable version of basic or OPL to put on my old laptop.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Alienware 17 R4 2017 review

These brilliant Lego posters show just what children's imaginations are capable of

Mac power user tips and hidden tricks

Comment réinitialiser votre PC, ordinateur portable ou tablette Windows ?