basic calculation

  amstrad 11:12 AM 15 Nov 12
Locked
Answered

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 PM 15 Nov 12
Answer

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 PM 15 Nov 12

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

If MOD(number)=0

Then ..do something

Else ..do 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 PM 15 Nov 12

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 AM 16 Nov 12

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

  Terry Brown 10:17 AM 18 Nov 12

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.

Terry

enter link description here

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

  Terry Brown 10:19 AM 18 Nov 12

http://uk.search.yahoo.com/search;ylt=A0geu8UEtahQ2n4A0pLBQx.?ei=UTF-8&fr=ush1-finance&p=zx81+emulator&SpellState=&fr2=sp-qrw-corr-top

Link did not work, try again

Terry

  Fermat's Theorem 21:10 PM 23 Nov 12

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 PM 24 Nov 12

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 PM 24 Nov 12

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 PM 28 Nov 12

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.

Advertisement

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

How to get Windows 10 now: how to download and install Windows 10 even if GWX.exe is missing

1995-2015: How technology has changed the world in 20 years

Nokia rolls out spherical camera for virtual reality apps

OS X Yosemite vs Windows 10: The Mac and PC operating systems go head to head UPDATED