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
SubbuUSAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mac-willCommented:
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

0
SubbuUSAAuthor Commented:
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:
0
wdosanjosCommented:
Alternatively:

int piecesPerKit = 100;
int employees = 503;
int kits = (int)Math.Ceiling((double)employees / piecesPerKit);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mac-willCommented:
wdosanjos response will also work but assuming you want to use the modulus operator.

The value will not matter.

int num_of_emp = 73;
int piecesPerKit = 100;

int num_of_kits = num_of_emp / piecesPerKit ;  // will yeild 0

if(num_of_emp % piecesPerKit != 0) // modulus will yield 73
{
 num_of_kits++;  // you will get 1 kit
}

Open in new window

0
SubbuUSAAuthor Commented:
Thanks to you both
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.