Solved

# Converting liters to pints and gallons

Posted on 2004-11-17
15,423 Views
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
0
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"
Else
usg = InputBox("Enter quantity in gallons: ", , 10)
lit = usg * 3.785
MsgBox usg & " gallons is equal to " & lit & " liters"
End If

Rajesh
0

LVL 55

Expert Comment

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).
0

LVL 48

Expert Comment

0

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

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
0

LVL 55

Assisted Solution

to convert liters to gallons and pints:

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

## Featured Post

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 …