Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2008
    Location
    Boston, MA
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    "Adding Machine" for Non-Metric Units

    I wrote this about 15 years ago and in the last few days, I updated it a bit. This will add non-metric units (for example pints, quarts, gallons, etc). This not only adds the amounts but will also reduce the total. For example, if you are entering "Volume" units and enter 7, 13 and 5 in the "quarts" column, (then click "Calculate"), your total will NOT be 25 quarts. (The calculator never has a total that is greater than 4 quarts (or 59 seconds or 23 hours, etc.)).Instead it takes the 25 quart total and converts it to 6 gallons and 1 quart.

    Please give this a try. Maybe in this computer-age, high tech, metricized world it is still needed.

    Code:
    <HTML>
    <!-- AUTHOR - Robert Gagnon -->
    
    <HEAD>
    <TITLE>NON-METRIC ADDING MACHINE</TITLE>
    <meta name="description" content="Calculator for Adding Non-Metric Units, Tons, Pounds, Ounces, Quarts Pints, Cups, Fluid Ounces, Miles, Yards, Feet, Inches">
    <meta name="keywords" content="Calculator for Adding Non-Metric Units, Tons, Pounds, Ounces, Quarts Pints, Cups, Fluid Ounces, Miles, Yards, Feet, Inches">
    <SCRIPT language="JavaScript">
    
    <!--
    if (parent.frames.length > 0) {
    parent.location.href = location.href;
    }
    // -->
    </SCRIPT>
    
    <script language="JavaScript">
    var choice=0;
    var totl=0;
    var t10=0;
    var t1=0;
    var t2=0;
    var t3=0;
    var t4=0;
    var ans1=0;var ans2=0;var ans3=0;var ans4=0;var ans5=0;
    var mod1=0;var mod2=0;var mod3=0;var mod4=0;var mod5=0;
    var int1=0; var int2=0; var int3=0; var int4=0; var int5=0; 
    var div1=0; var div2=0; var div3=0; var div4=0; var div5=0; 
    var GT1=0; var GT2=0; var GT3=0; var GT4=0; var GT5=0;
    var intgr=0;
    var sel = 0; <!-- sel is the selection-->
    var sel2 = 0; <!-- sel2 is the second selection-->
    var k=new Array('*****','Days', 'Hours', 'Minutes', 'Seconds', '*****','*****','Degrees', 'Minutes', 'Seconds', '*****','*****', 'Tons','Pounds', 'Ounces', 'Gallons','Quarts', 'Pints', 'Cups', 'Ounces','*****','Miles', 'Yards', 'Feet', 'Inches');
    var k2=new Array(0,0,86400, 3600, 60, 1, 0,0,3600,60, 1,0,0,32000, 16,1,128, 32, 16, 8, 1, 0,63360, 36, 12,1)
    
    var num=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    var lbl=new Array(0,"z1","z2","z3","z4","z5","z6","z7","z8","a1","a2","a3","a4","a5","a6","a7","a8","b1","b2","b3","b4","b5","b6","b7","b8",
    "c1","c2","c3","c4","c5","c6","c7","c8","d1","d2","d3","d4","d5","d6","d7","d8")
    var lbl2=new Array(0,"z1z","z2z","z3z","z4z","z5z","z6z","z7z","z8z","a1a","a2a","a3a","a4a","a5a","a6a","a7a","a8a",
    "b1b","b2b","b3b","b4b","b5b","b6b","b7b","b8b","c1c","c2c","c3c","c4c","c5c","c6c","c7c","c8c",
    "d1d","d2d","d3d","d4d","d5d","d6d","d7d","d8d")
    </SCRIPT>
    
    <script language="JavaScript">
    function cleer()
    {document.inbox.z1z.value="";document.inbox.z2z.value="";document.inbox.z3z.value="";document.inbox.z4z.value="";
    document.inbox.z5z.value="";document.inbox.z6z.value="";document.inbox.z7z.value="";document.inbox.z8z.value="";
    document.inbox.a1a.value="";document.inbox.b1b.value="";document.inbox.c1c.value="";document.inbox.d1d.value="";
    document.inbox.a2a.value="";document.inbox.b2b.value="";document.inbox.c2c.value="";document.inbox.d2d.value="";
    document.inbox.a3a.value="";document.inbox.b3b.value="";document.inbox.c3c.value="";document.inbox.d3d.value="";
    document.inbox.a4a.value="";document.inbox.b4b.value="";document.inbox.c4c.value="";document.inbox.d4d.value="";
    document.inbox.a5a.value="";document.inbox.b5b.value="";document.inbox.c5c.value="";document.inbox.d5d.value="";
    document.inbox.a6a.value="";document.inbox.b6b.value="";document.inbox.c6c.value="";document.inbox.d6d.value="";
    document.inbox.a7a.value="";document.inbox.b7b.value="";document.inbox.c7c.value="";document.inbox.d7d.value="";
    document.inbox.a8a.value="";document.inbox.b8b.value="";document.inbox.c8c.value="";document.inbox.d8d.value="";
    document.outbox.z9z.value="";
    document.outbox.a9a.value="";document.outbox.b9b.value="";document.outbox.c9c.value="";document.outbox.d9d.value="";
    }
    </script>
    
    <script language="JavaScript">
    function init()
    {if (choice==0){sel=0;sel2=1};
    if (choice==1){sel=5;sel2=6};
    if (choice==2){sel=10;sel2=11};
    if (choice==3){sel=15;sel2=16};
    if (choice==4){sel=20;sel2=21};
    
    document.inbox.z0z.value=k[sel];document.inbox2.z10z.value=k[sel];
    document.inbox.a0a.value=k[sel+1];document.inbox2.a10a.value=k[sel+1];
    document.inbox.b0b.value=k[sel+2];document.inbox2.b10b.value=k[sel+2];
    document.inbox.c0c.value=k[sel+3];document.inbox2.c10c.value=k[sel+3];
    document.inbox.d0d.value=k[sel+4];document.inbox2.d10d.value=k[sel+4];
    }
    </script>
    
    <script language="JavaScript">
    function calc()
    {
    t10=0;t1=0;t2=0;t3=0;t4=0;
    ct=1;GT=0;GT1=0;GT2=0;GT3=0;GT4=0;GT5=0;
    while(ct<9){
    lbl[ct]=eval(document.inbox[lbl2[ct]].value);
    if(lbl[ct]!=null||undefined) {num[ct]=lbl[ct];GT1=GT1+num[ct]};
    ct=ct+1;}
    GT1=GT1*k2[sel2];
    
    while(ct<17){
    lbl[ct]=eval(document.inbox[lbl2[ct]].value);  
    if(lbl[ct]!=null||undefined) {num[ct]=lbl[ct];GT2=GT2+num[ct]};
    ct=ct+1;}
    GT2=GT2*k2[sel2+1];
    
    while(ct<25){
    lbl[ct]=eval(document.inbox[lbl2[ct]].value);  
    if(lbl[ct]!=null||undefined) {num[ct]=lbl[ct];GT3=GT3+num[ct]};
    ct=ct+1;}
    GT3=GT3*k2[sel2+2];
    
    while(ct<33){
    lbl[ct]=eval(document.inbox[lbl2[ct]].value);  
    if(lbl[ct]!=null||undefined) {num[ct]=lbl[ct];GT4=GT4+num[ct]};
    ct=ct+1;}
    GT4=GT4*k2[sel2+3];
    
    while(ct<41){
    lbl[ct]=eval(document.inbox[lbl2[ct]].value);  
    if(lbl[ct]!=null||undefined) {num[ct]=lbl[ct];GT5=GT5+num[ct]};
    ct=ct+1;}
    GT5=GT5*k2[sel2+4];
    ct=0;
    
    GT=(GT1+GT2+GT3+GT4+GT5);
    <!-- Choices 0=time 1=angle 2 =weight 3=volume 4=length -->
    <!-- GT is the total number of the smallest unit (e.g seconds, ounces, inches) -->
    <!--- % is the remainder from a quotient GT5=GT%60; if GT = 3601 then GT5 = 1-->
    if (choice==0){
    div5=GT/60; int5=Math.floor(div5); mod5=Math.round((div5-int5)*60);
    div4=int5/60; int4=Math.floor(div4); mod4=Math.round((div4-int4)*60);
    div3=int4/24; int3=Math.floor(div3); mod3=Math.round((div3-int3)*24);
    div2=int3;
    GT5=mod5;GT4=mod4;GT3=mod3;GT2=div2;
    }
    
    if (choice==1){
    div5=GT/60; int5=Math.floor(div5); mod5=Math.round((div5-int5)*60);
    div4=int5/60; int4=Math.floor(div4); mod4=Math.round((div4-int4)*60);
    div3=int4;
    GT5=mod5;GT4=mod4;GT3=div3;
    }
    
    if (choice==2){
    div5=GT/16; int5=Math.floor(div5); mod5=Math.round((div5-int5)*16);
    div4=int5/2000; int4=Math.floor(div4); mod4=Math.round((div4-int4)*2000);
    div3=int4;
    GT5=mod5;GT4=mod4;GT3=div3;
    }
    
    if (choice==3){
    div5=GT/8; int5=Math.floor(div5); mod5=Math.round((div5-int5)*8);
    div4=int5/2; int4=Math.floor(div4); mod4=Math.round((div4-int4)*2);
    div3=int4/2; int3=Math.floor(div3); mod3=Math.round((div3-int3)*2);
    div2=int3/4; int2=Math.floor(div2); mod2=Math.round((div2-int2)*4);
    div1=int2;
    GT5=mod5;GT4=mod4;GT3=mod3;GT2=mod2;GT1=div1;
    }
    
    if (choice==4){
    div5=GT/12; int5=Math.floor(div5); mod5=Math.round((div5-int5)*12);
    div4=int5/3; int4=Math.floor(div4); mod4=Math.round((div4-int4)*3);
    div3=int4/1760; int3=Math.floor(div3); mod3=Math.round((div3-int3)*1760);
    div2=int3;
    GT5=mod5;GT4=mod4;GT3=mod3;GT2=div2;
    }
    
    document.outbox.z9z.value=GT1;
    document.outbox.a9a.value=GT2;
    document.outbox.b9b.value=GT3;
    document.outbox.c9c.value=GT4;
    document.outbox.d9d.value=GT5;
    
    if (choice!=3){document.outbox.z9z.value="*****"};
    if (choice==1 || choice==2){document.outbox.a9a.value="*****"};
    ct=9;
    
    }
    </SCRIPT>
    </HEAD>
    
    <body BGCOLOR="EEEEEE" alink="0000FF" vlink="FF0000">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" width="85%">
    <tr>
    <td>
    <TABLE><TR><TD colspan=2>
    <font face="Arial"><font color="CC0000">
    <b><p>
    <hr size=3 noshade width="55%" color="000066">
    <font size =6>
    <CENTER>Non-Metric<br>
    Adding &nbsp Machine</CENTER>
    <hr size=3 noshade width="55%" color="000066">
    <p>
    <B><font size =4><font color="000099">
    <p><CENTER>
    Click on a box below, then enter your data.<p>
    <BR><font size=2><font color="000000">
    This calculator has been extensively re-written.<br>
    If any problems, send an E-Mail to <a href= "mailto:wolf@1728.com" >wolf@1728.com</a><br>
    (Scroll down for more instructions.)
    <p>
    </CENTER>
    <valign=top><td width=50%>
    </TD></TR></TABLE>
    <CENTER>
    <TABLE><TR><TD colspan=2>
    <CENTER>
    <FORM>
    <!-- THESE ARE THE CHOICE BUTTONS -->
    <INPUT TYPE="button"  VALUE=" T I M E " SIZE =" 5" ONCLICK=" cleer(); choice=0; init(); return true"><P>
    <INPUT TYPE="button"  VALUE=" ANGLE "   SIZE =" 5" ONCLICK=" cleer(); choice=1; init(); return true"><P>
    <INPUT TYPE="button"  VALUE="WEIGHT"  SIZE =" 5" ONCLICK=" cleer(); choice=2; init(); return true"><P>
    <INPUT TYPE="button"  VALUE="VOLUME"  SIZE =" 5" ONCLICK=" cleer(); choice=3; init(); return true"><P>
    <INPUT TYPE="button"  VALUE=" LENGTH "  SIZE =" 5" ONCLICK=" cleer(); choice=4; init(); return true"><P>
    </FORM>
    <valign=top><td width=50%>
    </CENTER>
    </TD></TR></TABLE>
    </CENTER>
    
    <Center>
    <FORM NAME="inbox">
    <!-- THIS IS THE FIRST HEADER ROW -->
    <INPUT TYPE=“text” NAME="z0z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a0a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b0b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c0c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d0d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 1-->
    <INPUT TYPE=“text” NAME="z1z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a1a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b1b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c1c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d1d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 2-->
    <INPUT TYPE=“text” NAME="z2z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a2a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b2b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c2c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d2d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 3-->
    <INPUT TYPE=“text” NAME="z3z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a3a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b3b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c3c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d3d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 4-->
    <INPUT TYPE=“text” NAME="z4z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a4a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b4b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c4c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d4d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 5-->
    <INPUT TYPE=“text” NAME="z5z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a5a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b5b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c5c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d5d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 6-->
    <INPUT TYPE=“text” NAME="z6z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a6a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b6b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c6c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d6d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 7-->
    <INPUT TYPE=“text” NAME="z7z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a7a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b7b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c7c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d7d" VALUE="" SIZE=8><br>
    <!-- THIS IS INPUT ROW 8-->
    <INPUT TYPE=“text” NAME="z8z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a8a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b8b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c8c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d8d" VALUE="" SIZE=8><br>
    
    </FORM>
    
    <FORM>
    <!-- THIS IS THE RESET BUTTON -->
    <INPUT TYPE="button"  VALUE="Clear Boxes"  SIZE =" 20" ONCLICK=" cleer()">
            
    <!-- THIS IS THE CALCULATE BUTTON -->
    <INPUT TYPE="button"  VALUE="C A L C U L A T E"  SIZE =" 20" ONCLICK=" calc()">
    </FORM>
    
    
    
    
    
    <FORM NAME="outbox">
    <!-- THIS IS OUTPUT BOX 0-->
    <INPUT TYPE=“text” NAME="z9z"  SIZE=8>
    <!-- THIS IS OUTPUT BOX 1-->
    <INPUT TYPE=“text” NAME="a9a"  SIZE=8> 
    <!-- THIS IS OUTPUT BOX 2-->
    <INPUT TYPE=“text” NAME=b9b SIZE=8>
    <!-- THIS IS OUTPUT BOX 3-->
    <INPUT TYPE="text" NAME="c9c" SIZE=8>
    <!-- THIS IS OUTPUT BOX 4-->
    <INPUT TYPE="text" NAME="d9d" SIZE=8>
    </FORM>
    
    <FORM NAME="inbox2">
    <!-- THIS IS THE SECOND HEADER ROW -->
    <INPUT TYPE=“text” NAME="z10z" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="a10a" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="b10b" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="c10c" VALUE="" SIZE=8>
    <INPUT TYPE=“text” NAME="d10d" VALUE="" SIZE=8><br>
    </FORM>
    </CENTER>
    <CENTER>
    <TABLE><TR><TD colspan=2><font color="CC0000"><B>
    <font face=Arial><font size=5>
    <CENTER>I N S T R U C T I O N S</CENTER>
    <font color="000099"><font size=4>
    • Click on the type of units (Time, Angle, Weight, etc) that you want to add.<br>
    • Enter the numbers in the proper columns.<br>
    • Click "C A L C U L A T E" and it will add the columns.<p>
    How about an example?<br>
    Click on the "Time" button and then enter 67, 55 and 48 in the <i>minutes</i> column then enter 72, 99 and 38 in the <i>seconds</i> column.<br>
    Click "C A L C U L A T E" and look at the totals.  Notice you <i>don't</i> see 170 for the minute total nor 209 for the seconds total (even though that is what they equal).<br>
    In this example, you will <i>never</i> see a minute total nor a second total greater than 59.  What happens?  Well, 209 seconds are actually 3 minutes and 29 seconds so the calculator just puts 29 in the seconds column and "carries" 3 into the minutes column.<br> 
    We have a total of 173 for the minutes column, which is actually (2 hours and 53 minutes), so we see 53 as the minute total and it carries the 2 hours into the next column.<br>
    Pretty neat huh?<p>
     
    
    
    
    <valign=top><td width=50%>
    </CENTER>
    </TD></TR></TABLE>
    </CENTER>
    
    <font color="#000000">
    <hr size=3 noshade width="55%" color="000066">
    <font size=4>
    <center><a href="index.htm">Return To Home Page</a><p>
    Copyright © 1999 - 
    <script>
    var xright=new Date;
    document.writeln(xright.getFullYear());
    </script>
    &#160 &#160 1728 Software Systems
    
    
    </center></td></tr></table>
    </Center>
    </body>
    </html>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    What about all of the other non-metric measures - for length you have miles, yards, feet and inches but have omitted rods, chains, furlongs etc. all of which fill the gap between yards and miles. For weight you have left out the most common measure - stones.

    You also haven't allowed for the fact that the US uses a smaller gallon than the rest of the world where 25 quarts is 4 gallons and 1 quart.

    The script could also do with some work on the HTML as it is still using HTML 3.2 whereas HTML 4 became the standard in 1997.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    wolf1728 (04-23-2014)

  • #3
    New Coder
    Join Date
    Aug 2008
    Location
    Boston, MA
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you felgall for your comments. I probably won't include those lengths you suggested because I don't think they will be used by too many people. One "problem" with my calculator is that it will automatically carry over into the next "left-hand" column no matter how common or uncommon that unit is used. I wouldn't want someone to calculate that the new rug they are ordering should be 1.66 by 2.33 fathoms.
    I really like your idea about including "stones" and "British Imperial" units in the calculator. I think that's something worth pursuing.
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •