Link to home
Start Free TrialLog in
Avatar of SubbuUSA
SubbuUSAFlag for United States of America

asked on

C# Question on Modulus

I have a requirment for my new customer in our new e commerce website..I know I have to use modulus for solving this problem but need some help.

I have a requirement like

1 kit will have 100 pieces.
if Number of employees is 500 i have to allocate 5kits. if employees are 503 then I have to allocate 6 kits.

thanks in advance for helping me
Avatar of mac-will
mac-will
Flag of Canada image

Modulus is the remainder.

500 / 100 = 5

500 % 100 = 0

503 / 100 = 5

503 % 100 = 3


int num_of_emp = 503;

int num_of_kits = num_of_emp / 100;

if(num_of_emp % 100 != 0)
{
 num_of_kits++;
}

Open in new window

Avatar of SubbuUSA

ASKER

thanks.  what if I have a configurable value instead of 100. say 5 or 10. what if the value 503 is less than the configurable value.

Thanks for your response mac-will:
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to you both