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 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Simple calculation standalone app

    Hey guys,
    I just ran into your forum site and would like to post a request. Don't know if Iwill get flamed or not for this. But I work in a small business and need to do these calculations on a very regular basis. Right now I am doing this manually, but I would like to get this automated and get a tiny app for this. If anybody would like to help, that would be deeply appreciated.

    Thank you.

    n= user input

    if (n<=300)
    i=((30*n)/100)

    if (n>300&&n<=1000)
    r=n-300
    i=((30*n)/100)
    i=i+((25*r)/100)

    if (n>1000)
    r=n-300
    s=n-700
    i=((30*n)/100)
    i=i+((25*r)/100)
    i=i+((20*s)/100)

    print i


    input would just be a user form and output would be the screen.
    thanks.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It appears that your conditionals are properly formatted and only needed to be placed within a function and called...

    Try this:
    Code:
    <script type="text/javascript">
     <!--//
      function calculate(n){
        if (n<=300){
            i=((30*n)/100);
        }
    
        if (n>300&&n<=1000){
            r=n-300;
            i=((30*n)/100);
            i=i+((25*r)/100);
        }
    
        if (n>1000){
            r=n-300;
            s=n-700;
            i=((30*n)/100);
            i=i+((25*r)/100);
            i=i+((20*s)/100);
        }   document.write(i);
      }
     //-->
    </script>
    </head>
    
    <body>
    <form>
    <input type="text" name="userInput">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
    </form>
    .....Willy

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a ton willy. that works. I just coded it in php myself and now thanks to you i can use it right from my desktop instead of hosting it on a php enabled server somewhere.

  • #4
    New Coder
    Join Date
    Nov 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Hi,
    I just typed this up and somehow nothing happens in IE or Mozilla...
    Code:
    <HTML>
    <head>
    <script type="text/javascript">
     <!--//
    
      function calculate(n){
        if (n<=300){
            i=(.3*n);
        }
    
        if (n>300&&n<=1000){
            r=n-300;
            i=(.30*300);
            i=i+((.25*r);
        }
    
        if (n>1000){
            s=n-1000;
            i=(.30*300);
            i=i+(.25*700);
            i=i+(.20*s);
        }  
    
     document.write(i);
      }
     //-->
    </script>
    </head>
    
    <body>
    <form>
    <input type="text" name="userInput">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
    </form>
    </body>
    </html>
    Last edited by abhic; 11-05-2004 at 07:08 PM.

  • #5
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Had an extra parenthesis on line 14.

    I changed it a bit so that the form stays after calculation. If you don't like that just remove the extra parenthesis from the orig.

    Code:
    <HTML>
    <head>
    <script type="text/javascript">
     <!--//
    
      function calculate(n){
        if (n<=300){
            i=(.3*n);
        }
    
        if (n>300&&n<=1000){
            r=n-300;
            i=(.30*300);
            i=i+(.25*r);
        }
    
        if (n>1000){
            s=n-1000;
            i=(.30*300);
            i=i+(.25*700);
            i=i+(.20*s);
        }  
    
     document.getElementById('answer').innerHTML=(i);
      }
     //-->
    </script>
    </head>
    
    <body>
    <form>
    <input type="text" name="userInput">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
    <div id="answer"></div>
    </form>
    </body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #6
    New Coder
    Join Date
    Nov 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a ton. It works. I am now trying to get more than one rate calculated (actually 5). Let's see if that works, else it would be great if the community could help.

    This is a great place for people with no skills but real needs.

  • #7
    New Coder
    Join Date
    Nov 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got this, very lame but it kinda works. Is there a way I can get each one to get calculated with their own values instead of clicking calculate separately for each value...

    Code:
    <script type="text/javascript">
     <!--//
    
      function calculate(n){
        if (n<=300){
            i=(.3*n);
        }
    
        if (n>300&&n<=1000){
            r=n-300;
            i=(.30*300);
            i=i+(.25*r);
        }
    
        if (n>1000){
            s=n-1000;
            i=(.30*300);
            i=i+(.25*700);
            i=i+(.20*s);
        }  
    
     document.getElementById('answer').innerHTML=(i);
      }
     //-->
    </script>
    </head>
    
    <body>
    <form>
    <input type="text" name="userInput">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
    
    <input type="text" name="userInput2">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput2.value)">
    
    <input type="text" name="userInput3">
    <input type="button" value="Calculate" onclick="calculate(this.form.userInput3.value)">
    <div id="answer"></div>
    </form>


  •  

    Posting Permissions

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