IonicWind Software

IWBasic => General Questions => Topic started by: Brian on January 07, 2017, 05:05:48 AM

Title: Finding a remainder
Post by: Brian on January 07, 2017, 05:05:48 AM
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
Title: Re: Finding a remainder
Post by: Egil on January 07, 2017, 07:16:17 AM
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



Title: Re: Finding a remainder
Post by: Egil on January 07, 2017, 08:27:16 AM
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
Title: Re: Finding a remainder
Post by: ckoehn on January 07, 2017, 08:59:40 AM
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
Title: Re: Finding a remainder
Post by: Brian on January 07, 2017, 09:18:48 AM
Thanks, Chaps,

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

Brian
Title: Re: Finding a remainder
Post by: billhsln on January 07, 2017, 09:50:19 AM
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
Title: Re: Finding a remainder
Post by: Egil on January 07, 2017, 10:17:11 AM
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.
Title: Re: Finding a remainder
Post by: ckoehn on January 07, 2017, 02:06:16 PM
Bill,

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

Later,
Clint