April 18, 2024, 12:44:12 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Finding a remainder

Started by Brian, January 07, 2017, 05:05:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

If I have a number, say 100, and divide that by 16, the answer would be 6.25

How do I take that answer and determine that there is a whole number AND a remainder?

Many thanks,

Brian

Egil

January 07, 2017, 07:16:17 AM #1 Last Edit: January 07, 2017, 07:18:18 AM by Egil
Hi Brian,

The CB code below does what you are after, but I was not able to get the same code to work with IWB. The decimals only show "00".
Not yet been able to figure out why.

Egil

openconsole

def a:int
def b:float

a=100/16

b=(100/16)-a

print"int(100/16)=",a
print"Remainder: ", b

do:until inkey$<>""
closeconsole
end



Support Amateur Radio  -  Have a ham  for dinner!

Egil

Brian,

Modified the CB code above to read:
openconsole

def a:int
def b:float

a=100/16
b=100.00/16.00

print"100/16 = ",a
print"Remainder: ", b-a

do:until inkey$<>""
closeconsole
end


Now the code works both with CB and IWB.


Good luck,
Egil
Support Amateur Radio  -  Have a ham  for dinner!

ckoehn

Or was this what you had in mind..
openconsole

double a=100.0/16.0
double b=(a-int(a))*16.0

print "100/16=",int(a)
print "Remainder=:",int(b)

do:until inkey$<>""

closeconsole


Later,
Clint

Brian

Thanks, Chaps,

I'll have a look at all the answers later. Just at the wife's beck and call at the moment!

Brian

billhsln

Way to much work, see:  % - Modulus-The remainder of an integer division.  Under Operators and Mathematical Expressions.  Does exactly what you are looking to do and is built into the language.

answer = 155 % 100.  returns 55.

Bill
When all else fails, get a bigger hammer.

Egil

Brian,
You probably want what both Clint and Bill are suggestion. I was thinking decimals only, not the remainder of an integer division.
But anyway, now you have suggestions for both ways.
Support Amateur Radio  -  Have a ham  for dinner!

ckoehn

Bill,

Looks like I had a senior moment and I'm not even a senior.  Your right, and I knew that. :-[

Later,
Clint