I have made a unit conversion software that can right now only do grams ounces and pounds. i have accomplised the grams part but now i cant seem to get the oz part. what am i doing wrong?
sub oz
dim as single grams,ozz
dim as integer pounds
print"you can convert ounces to grams and pounds here"
input"how many ounces" ; ozz
grams = ozz / 28.3495
if ozz < 16.0 then
pounds = 0
else
pounds = fix (ozz * 16.0) * 1
ozz = ozz - (pounds * 16)
endif
print ozz;"ounces are equal to"
print grams;"grams"
print pounds; "pounds"
end sub
sleep
When you get stuck on a thing like this something to try is to forget for a while that you have a computer.
Solve the problem manually; pen, paper, and calculator. Do this 2 or 3 times until you get correct answers and find the best method. Then write down step by step, in English (or whatever your native language is) the method that you used.
Then take those instructions and "translate" them into BASIC
sub oz()
#Define float Single
dim as float grams,ozz
dim as float pounds_dec
Type lb_oz
lb_ As float
oz_ As float
End Type
Dim pounds_oz As lb_oz
Const _lb2kg = 0.453592370 '1.0 lb = 0.453592370 kg (EXACTLY)
Const _lb2oz = 16 'EXACTLY
Const _lb2gm = _lb2kg*1000
Print "Convert ounces to grams, decimal pounds and pounds with fractional ounces."
Input "How many ounces " ; ozz
grams = ozz/_lb2oz*_lb2gm
pounds_dec = ozz/_lb2oz
pounds_oz.lb_ = fix(pounds_dec)
pounds_oz.oz_ = (pounds_dec - pounds_oz.lb_)*_lb2oz
print Using "########.### ounces are equal to";ozz
print Using "########.### grams";grams
print Using "########.### pounds";pounds_dec
print Using "######## pounds ####.# ounces ";pounds_oz.lb_;pounds_oz.oz_
end Sub
oz
Sleep