Beginners' Tech Help
It's free to register, to post a question or to start / join a discussion
basic calculation
Likes # 0
Posted November 15, 2012 at 11:12AM
In basic, is there a check to see that the result of a calculation is a whole number and do something else if not?
- Tags:
- z80
- basic
- calculation
Likes # 1
Posted November 15, 2012 at 7:33PM
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.
Likes # 1
Posted November 15, 2012 at 7:52PM
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
Posted November 16, 2012 at 8:30AM
Thanks for the info. I'm not sure if the ZX 81 supports ( MOD ) we'll find out
Likes # 0
Posted November 18, 2012 at 10:17AM
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"
Likes # 0
Posted November 18, 2012 at 10:19AM
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
Likes # 0
Posted November 23, 2012 at 9:10PM
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. :-)
Likes # 0
Posted November 24, 2012 at 6:58PM
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.
Likes # 0
Posted November 24, 2012 at 8:57PM
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
Posted November 28, 2012 at 12:36PM
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.
Likes # 0
Posted November 28, 2012 at 7:08PM
amstrad
Have you tried here?-:
Thanks for the info about your project - those were the days. I even started to learn machine code on that machine!! Progressed to Commodore 64 then Amiga 500+ (along with AMOS basic).
Reply to this topic
This thread has been locked.



