...

# Simple calculation standalone app

abhic
11-05-2004, 05:55 PM
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.

Willy Duitt
11-05-2004, 06:20 PM
It appears that your conditionals are properly formatted and only needed to be placed within a function and called...

Try this:

<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>

<body>
<form>
<input type="text" name="userInput">
<input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
</form>

.....Willy

abhic
11-05-2004, 08:01 PM
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.

abhic
11-05-2004, 08:05 PM
Hi,
I just typed this up and somehow nothing happens in IE or Mozilla...

<HTML>
<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>

<body>
<form>
<input type="text" name="userInput">
<input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
</form>
</body>
</html>

Basscyst
11-05-2004, 08:13 PM
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.

<HTML>
<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);
}

}
//-->
</script>

<body>
<form>
<input type="text" name="userInput">
<input type="button" value="Calculate" onclick="calculate(this.form.userInput.value)">
</form>
</body>
</html>

Basscyst

abhic
11-05-2004, 08:16 PM
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.

abhic
11-05-2004, 08:29 PM
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...

<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);
}

}
//-->
</script>

<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)">