Converting liters to pints and gallons

Posted on 2004-11-17
Last Modified: 2012-06-27
Can anyone assist me ian writting a code for converting liters to pints and gallons,

I came up with this, however I can't seem to place it in a code.

 U.S. gallon = 3.7854 liters. One liter = .264 U.S. gallon.
The formula for converting liters to U.S. gallons is:
Liters ÷ 3.7854 = U.S. gallons
Convert U.S. gallons to liters with the formula:
U.S. gallons x 3.785 = liters
Question by:jahsexy18
    LVL 24

    Accepted Solution

    Hi jahsexy18,

    if the formula you have given is correct then it would be something like this in vb

    Dim usg As Double, lit As Double
    If MsgBox("Do you want to convert liters to gallon", vbYesNo) = vbYes Then
    lit = InputBox("Enter quantity in liters: ", , 10)
    usg = lit / 3.7854
    MsgBox lit & " liters is equal to " & usg & " gallons"
    usg = InputBox("Enter quantity in gallons: ", , 10)
    lit = usg * 3.785
    MsgBox usg & " gallons is equal to " & lit & " liters"
    End If

    LVL 55

    Expert Comment

    by:Jaime Olivares
    It is a simple conversion, but, which programming language?

    I don't see pints considerations in your formulas (I guess 1 pints = 1/8 gallon).
    LVL 48

    Expert Comment


    Author Comment

    I am not sure I understand how this fit, can u please explain.  I have already created  auser interface, which has three labels

    1. Input for liters
    2. read only for pints
    3. read only for gallons

    Also I have two buttons one to reset and one to compute

    My problem is writtin the code to convert liters to pint and gallons.

    u get liters to pint when u multiply liters by 2.1134
    LVL 55

    Assisted Solution

    by:Jaime Olivares
    to convert liters to gallons and pints:

    gallons = fix(liters / 3.7854)
    pints = (liters / 3.7854 - gallons) * 8

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now