NEED MORE HELP WITH UNIT COVERSION SOFTWARE

New to FreeBASIC? Post your questions here.
Post Reply
nosman
Posts: 15
Joined: Aug 04, 2010 17:06

NEED MORE HELP WITH UNIT COVERSION SOFTWARE

Post by nosman »

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?

Code: Select all

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
j_milton
Posts: 458
Joined: Feb 11, 2010 17:35

Post by j_milton »

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
nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Post by nobozoz »

Code: Select all

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

Post Reply