flashy_lord
Member
hey gals
this whole concept with MOD and integer division has me tangled up, I have to write some code that will convert ounces to remaining gallons, quarts, pints, cups and ounces using integer division and mod operator
this are the converting factors
one gallon = 128 ounces
one quart = 32 ounces
one pint = 16 ounces
one cup = 8 ounces
for some reason my logic is not flowing correctly, can anyone help me straighten this out? my code is as follows
Public Class LiquidCalculator
Private Sub convertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertButton.Click
Dim Gallons, Quarts, Pints, Cups, Ounce, Tbox As Integer
Tbox = Val(OunceTextBox.Text)
Gallons = (Tbox \ 128)
GlLabel.Text = Gallons
Quarts = (Gallons \ 32) Mod 32
QtLabel.Text = Quarts
Pints = (Quarts \ 16) Mod 16
PtLabel.Text = Pints
Cups = (Pints \ 8) Mod 8
CpLabel.Text = Cups
Ounce = (Cups \ 4) Mod 4
End Sub
End Class
I have also attached the solution to this thread in case that helps making more sense
View attachment liquid converter.zip
this whole concept with MOD and integer division has me tangled up, I have to write some code that will convert ounces to remaining gallons, quarts, pints, cups and ounces using integer division and mod operator
this are the converting factors
one gallon = 128 ounces
one quart = 32 ounces
one pint = 16 ounces
one cup = 8 ounces
for some reason my logic is not flowing correctly, can anyone help me straighten this out? my code is as follows
Public Class LiquidCalculator
Private Sub convertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertButton.Click
Dim Gallons, Quarts, Pints, Cups, Ounce, Tbox As Integer
Tbox = Val(OunceTextBox.Text)
Gallons = (Tbox \ 128)
GlLabel.Text = Gallons
Quarts = (Gallons \ 32) Mod 32
QtLabel.Text = Quarts
Pints = (Quarts \ 16) Mod 16
PtLabel.Text = Pints
Cups = (Pints \ 8) Mod 8
CpLabel.Text = Cups
Ounce = (Cups \ 4) Mod 4
End Sub
End Class
I have also attached the solution to this thread in case that helps making more sense
View attachment liquid converter.zip