Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3968892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:53:52+00:00 2026-05-20T03:53:52+00:00

Given an amount in ml and 3 pack sizes (20ml, 200ml and 1000ml) I’d

  • 0

Given an amount in ml and 3 pack sizes (20ml, 200ml and 1000ml) I’d like to calculate how many of each packs are needed to fulfill the total amount.

E.g.

Amount = 3210ml
1000ml = 3 packs
200ml = 1 pack
20ml = 1 pack (always round up to nearest quantity)

This is pretty much just like a change calculator, and I’m looking for the right way to do it.

Here’s my attempt

public class PackSizeCalculator
{
    private const int LargePackSize = 1000;
    private const int MediumPackSize = 200;
    private const int SmallPackSize = 20;

    public int LargePacks {get; set;}
    public int MediumPacks {get; set;}
    public int SmallPacks {get; set;}

    public  PackSizeCalculator(int amount)
    {
        int remainder = amount;

        while(remainder > 0) {
            if(remainder >= LargePackSize)
            {
                LargePacks = remainder / LargePackSize;
                remainder = remainder % LargePackSize;
            }
            else if(remainder >= MediumPackSize)
            {
                MediumPacks = remainder / MediumPackSize;
                remainder = remainder % MediumPackSize;
            }
            else if(remainder > SmallPackSize)
            {
                if(remainder % SmallPackSize == 0)
                {
                    SmallPacks = (remainder / SmallPackSize);
                }
                else {
                    SmallPacks = (remainder / SmallPackSize) + 1;
                }
                remainder = 0;
            }
            else {
                SmallPacks = 1;
                remainder = 0;
            }
        }
    }
}

Is this a good way to go about it or would you recommend something different?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:53:53+00:00Added an answer on May 20, 2026 at 3:53 am

    Something like this:

    const int LARGE_PACK = 1000;
    const int MEDIUM_PACK = 200;
    const int SMALL_PACK = 20;
    
    int largePacks = (int)(Amount / LARGE_PACK);
    int mediumPacks = (int)((Amount % LARGE_PACK) / MEDIUM_PACK);
    int smallPacks = (int)ceil(((float)((Amount % LARGE_PACK) % MEDIUM_PACK) / SMALL_PACK));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Mathematically we can solve it like Given Amount / Total Amount * 100 to
How to calculate the monthly fee on a loan? Given is: a: an amount
Given an amount of days, say 25, convert it into a duration text such
If the amount of data stored within a given field of a database is
I know add() adds the specified (signed) amount of time to the given time
I have a table recording the amount of data transferred by a given service
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a DateTime representing a person's birthday, how do I calculate their age in
Given an absolute or relative path (in a Unix-like system), I would like to
I would like to start several processes as children of a given supervisor. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.