We use cookies to provide you with a better experience. If you continue to use this site, we'll assume you're happy with this. Alternatively, click here to find out how to manage these cookies

Contact Forum Editor

Send an email to our Forum Editor:

PLEASE NOTE: Your name is used only to let the Forum Editor know who sent the message. Both your name and email address will not be used for any other purpose.

# Beginners' Tech Help

It's free to register, to post a question or to start / join a discussion

# basic calculation

Resolved

Likes # 0

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

Likes # 0

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

Likes # 1

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

Likes # 1

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.

Likes # 0

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

Terry Brown

Likes # 0

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

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

Likes # 0

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

Likes # 0

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

Likes # 0

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

Likes # 0

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!

Likes # 0

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.