Simple unit converter help.
Posted: Tue May 05, 2009 2:19 pm
Usually I ask a teacher or fellow student but since I'm at home, and bored, I'm asking you guys for help.
I have taken several beginning programming classes (c, c++, javascript, python, and php), understand how the logic works and such. But seem to always miss something that completely stops everything from working.
I need someone else to look it over really quick and point out any errors in syntax or logic that I missed.
Thanks
A very simple unit converter that converts metric to us. Just weight in oz/lbs and length in cm/in.
Requirements:
No need for labels such as oz, cm, in, lbs. Just place the number in the desired box and let the computer do the rest.
Desired results:
Place a number in metric length and have it convert to us length
same thing for weight,
Place a number in us length and have it convert to metric length
same thing for weight.
Aesthetics don't matter, I just need results and can then make it pretty later. I don't care where the output pop up, as long as it actually pops up
Questions:
If I could get an output, would not putting any values in the none used length/weight produce garbage results?
Will this work Metric -> US and Metric <- US?
p.s. This is an experiment project I'm doing for fun.
/edit - how to I get the color syntax in the code box to show to facilitate reading?
I have taken several beginning programming classes (c, c++, javascript, python, and php), understand how the logic works and such. But seem to always miss something that completely stops everything from working.
I need someone else to look it over really quick and point out any errors in syntax or logic that I missed.
Thanks
A very simple unit converter that converts metric to us. Just weight in oz/lbs and length in cm/in.
Requirements:
No need for labels such as oz, cm, in, lbs. Just place the number in the desired box and let the computer do the rest.
Desired results:
Place a number in metric length and have it convert to us length
same thing for weight,
Place a number in us length and have it convert to metric length
same thing for weight.
Aesthetics don't matter, I just need results and can then make it pretty later. I don't care where the output pop up, as long as it actually pops up
Questions:
If I could get an output, would not putting any values in the none used length/weight produce garbage results?
Will this work Metric -> US and Metric <- US?
p.s. This is an experiment project I'm doing for fun.
Code: Select all
<?php
//variables
$oz ="";
$cm ="";
$lbs ="";
$in ="";
//calculations
oz / 16 = lbs;
centimeters * 0.3937 = inches;
?>
<div>
<form action="?" method="post">
--------------METRIC------------------------------------US----------<br />
weight <input type="text" name="oz" size="4">
length <input type="text" name="cm" size="4">
<input type="submit" name="button" value="submit" />
weight <input type="text" name="lbs" size="4">
length <input type="text" name="in" size="4">
</form>
<? echo "oz" . 'oz(' . "lbs" . 'lbs)' . '-' . "cm" . 'cm(' . "in" . 'in)';?>
<div>