|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding | |
Profit Calculator
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||
|
New to Overclock.net
|
I was lately helping my uncle and were selling computer hardware and parts to people, so then I was tired of calculating with a calculator so I scripted something; it probably is not a full program as it is not an executable file, but I used Javascript and Xhtml 1.0 to code it. Anyone who wishes to use it may and you can also edit it to your liking. I hope I did an alright job. I have also validated it. I hope its useful.
PLEASE NOTE: The sales tax part is the New York Sales Tax, therefore, you will have to change that depending on where you live, you can also edited so that you can add the sales tax yourself. If you want, I can do further editing to it. You probably need JavaScript to use this, as well. I have made a new version of it, please check it out and I have revised the V0 adding the stars, so you know those are the ones you are suppose to put information on. On the second one, I made it so you can try a different sales tax, though default is 8.375%. Please feedback on what you think. Thank you. If there are any errors or incorrect formulas, please tell me to fix or fix for me and tell me. Thank you. I hope V1 is much more useful. Profit Calculator V0 REV0.1 Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This scripting was scripted by ninjinsamax3. This is opened sourced, so please edited as you wish, but please give some credit. Thank you. -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see www.w3.org" />
<title>Profit Calculator V0 REV0.1</title>
<style type="text/css">
/*<![CDATA[*/
span {font-weight:bold;}
img {border:0px;}
/*]]>*/
</style>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
function calculate()
{
var stateTax = 0.08375;
var shPrice = Number(document.form.shippingPrice.value);
var sPrice = Number(document.form.salesPrice.value);
var pWanted = Number(document.form.profitWanted.value) / 100;
var priceWithProfitWanted = (sPrice * pWanted) + sPrice;
var priceWithStateTax = (priceWithProfitWanted * stateTax) + priceWithProfitWanted;
var fPrice = priceWithStateTax + shPrice;
var pMade = fPrice - sPrice -shPrice;
document.form.finalPrice.value = fPrice.toFixed(2);
document.form.roundedPrice.value = fPrice.toFixed(0);
document.form.profitMade.value = pMade.toFixed(2);
document.form.roundedProfit.value = pMade.toFixed(0);
}
function formReset()
{
document.getElementById("form").reset()
}
//]]>
</script>
<table>
<tr>
<td>
<form name="form" id="form" action=""><p><span>*Sales Price: $</span><input type="text" name="salesPrice" value="" size="5" /><br />
<span>*Profit Wanted: </span><input type="text" name="profitWanted" value="" size="5" /><span>%</span><br />
<span>*Shipping Price: $</span><input type="text" name="shippingPrice" value="" size="5" /><br />
<span>Final Price: $</span><input type="text" name="finalPrice" value="" size="5" /><br />
<span>Rounded Price: $</span><input type="text" name="roundedPrice" value="" size="5" /><br />
<span>Profit Made: $</span><input type="text" name="profitMade" value="" size="5" /><br />
<span>Rounded Profit: $</span><input type="text" name="roundedProfit" value="" size="5" />
</p>
<p><input type="button" name="calculateButton" value="Calculate" onclick="calculate()" /> <input type="button" name="resetButton" value="Reset" onclick="formReset()" /></p>
</form>
</td>
</tr>
</table>
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p>
</body>
</html>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This scripting was scripted by ninjinsamax3. This is opened sourced, so please edited as you wish, but please give some credit. Thank you. -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see www.w3.org" />
<title>Profit Calculator V0 REV0.0</title>
<style type="text/css">
/*<![CDATA[*/
span {font-weight:bold;}
img {border:0px;}
/*]]>*/
</style>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
function calculateTax(tax, price)
{
return tax * price;
}
function calculateProfit(price, profit)
{
return (price * profit) / 100;
}
function calculate()
{
var sTax = Number(document.form.stateTax.value) / 100;
var sPrice = Number(document.form.salesPrice.value);
var pWanted = Number(document.form.profitWanted.value);
var shPrice = Number(document.form.shippingPrice.value);
var saTax = calculateTax(sTax, sPrice);
var pPrice = calculateProfit(sPrice, pWanted) + sPrice;
var fPrice = pPrice + calculateTax(sTax, pPrice) +shPrice;
var fPST = fPrice - shPrice - pPrice;
var sTD = fPST - saTax;
var pMade = fPrice - shPrice - sPrice;
document.form.salesTax.value = saTax.toFixed(2)
document.form.finalPrice.value = fPrice.toFixed(2);
document.form.finalPriceSalesTax.value = fPST.toFixed(2);
document.form.roundedPrice.value = fPrice.toFixed(0);
document.form.roundedPriceSalesTax.value = fPST.toFixed(2);
document.form.salesTaxDifference.value = sTD.toFixed(2);
document.form.profitMade.value = pMade.toFixed(2);
document.form.roundedProfit.value = pMade.toFixed(0);
}
function formReset()
{
document.getElementById("form").reset()
}
//]]>
</script>
<table>
<tr>
<td>
<form name="form" id="form" action=""><p><span>*State Tax: </span><input type="text" name="stateTax" value="8.375" size="5" /><span>%</span><br />
<span>*Sales Price: $</span><input type="text" name="salesPrice" value="" size="5" /><br />
<span>*Profit Wanted: </span><input type="text" name="profitWanted" value="" size="5" /><span>%</span><br />
<span>*Shipping Price: $</span><input type="text" name="shippingPrice" value="" size="5" /><br />
<span>Sales Tax: $</span><input type="text" name="salesTax" value="" size="5" /><span></span><br />
<span>Final Price: $</span><input type="text" name="finalPrice" value="" size="5" /><br />
<span>Final Price Sales Tax: $</span><input type="text" name="finalPriceSalesTax" value="" size="5" /><span></span><br />
<span>Rounded Price: $</span><input type="text" name="roundedPrice" value="" size="5" /><br />
<span>Rounded Price Sales Tax: </span><input type="text" name="roundedPriceSalesTax" value="" size="5" /><span></span><br />
<span>Profit Made: $</span><input type="text" name="profitMade" value="" size="5" /><br />
<span>Rounded Profit: $</span><input type="text" name="roundedProfit" value="" size="5" /><br />
<span>Original & Final Sales Tax Difference: $</span><input type="text" name="salesTaxDifference" value="" size="5" />
</p>
<p><input type="button" name="calculateButton" value="Calculate" onclick="calculate()" /> <input type="button" name="resetButton" value="Reset" onclick="formReset()" /></p>
</form>
</td>
</tr>
</table>
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></p>
</body>
</html>
__________________
キャントジャパンニースのプライド!! 初音ミクの歌を聞かないけど、 彼女のキャラがズット大好きで、 可愛くてたまらないと思うんです。 Program: Profit Calculator
Last edited by ninjinsamax3 : 02-11-08 at 10:33 PM. |
||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||
|
Programmer
|
pretty simple, yet effective...
I could toss something together in C++ so you can have a stand alone exe file... interested?
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||||
|
|
|
|
#3 (permalink) | ||||||||||||
|
New to Overclock.net
|
Yeah. I never learned C++, but only Java and yet, I do not know how to make Jar files because making one was too difficult for me. If you could give some pointers for the C++ and executable files that would be nice. Thank you in advance.
__________________
キャントジャパンニースのプライド!! 初音ミクの歌を聞かないけど、 彼女のキャラがズット大好きで、 可愛くてたまらないと思うんです。 Program: Profit Calculator
|
||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||
|
Programmer
|
yeah sure...
I'll toss something together, and give you the source and the exe... Go download "bloodshed" its a fairly easy to use c++ compiler, and its free...
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||||
|
|
|
|
#5 (permalink) | |||||||||||
|
Programmer
|
i have something going, but its not quite working yet...
Do you charge tax before or after shipping costs?? also, you state that the tax is 0.08375. Does this mean 8.375 cents per dollar?
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||
|
Programmer
|
Quote:
I live in Oregon, so tax isn't an issue, or something that i have to deal with often :P
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||
|
Programmer
|
Here is the code i put together. The logic is the same as javascript, and similar with declaring variables. "float" gives the variable your calculating more precision, so you can apply cents the the cost.
Let me know if there's something wrong with it, or you need clarification with something... i also attached the exe file, so you can play around with it and verify it. ![]() Code:
#include <iostream> //Required if your program does any I/O
#include <string> //Required if your program uses C++ strings
#include <iomanip> //Allows I/O Manipulation
using namespace std; //Required for ANSI C++ 1998 standard.
int main (int argc, char **argv) //Arguments to main are command line arguments
{
char reply; //A character variable to hold user input
float stateTax = 0.08375;
float profitWanted;
float costPrice;
float shippingCost;
float salePriceWithTax;
float costPriceWithProfit;
float priceAterTaxAndShipping;
cout << "Welcom to JoBlo69's Profit Calculator!" << endl;
cout << 'n';
cout << "Please enter Item's price : ";
cin >> costPrice;
cout << "Please enter shipping cost : ";
cin >> shippingCost;
cout << "Enter profit wanted : ";
cin >> profitWanted;
cout << 'n';
salePriceWithTax = (stateTax * costPrice) + costPrice;
costPriceWithProfit = salePriceWithTax + profitWanted;
priceAterTaxAndShipping = salePriceWithTax + shippingCost;
cout << "Cost of item with tax : " << salePriceWithTax << endl;
cout << 'n';
cout << "Cost of item with profit, and tax : " << costPriceWithProfit << endl;
cout << 'n';
cout << "Cost of item with profit, tax and shipping : " << priceAterTaxAndShipping << endl;
cout << 'n';
cout << "Press any key followed by 'Enter' to quit: ";
cin >> reply;
return 0;
}
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||||
|
|
|
|
#8 (permalink) | ||||||||||||
|
New to Overclock.net
|
That's nice.
C++ is a little different from Java, but what did you use to create the executable file?
__________________
キャントジャパンニースのプライド!! 初音ミクの歌を聞かないけど、 彼女のキャラがズット大好きで、 可愛くてたまらないと思うんです。 Program: Profit Calculator
|
||||||||||||
|
|
|
|
|
#9 (permalink) | |||||||||||
|
Programmer
|
i used "bloodshed" its an open source C++ compiler.
It looks like a really advanced note pad app. But with options to compile your code into an .exe... The text file is simply a .cpp file. Think of it as a .txt file with a different file extension. The compiler, reads this file, and makes another file (the .exe) on the most basic level, machine code, aka binary 1's and 0's.
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||||
|
|
|
|
#10 (permalink) | ||||||||||||
|
New to Overclock.net
|
Only for C++ right and not for Java? I wish there was something for Java easy to do, since I'm not familiar with C++, I can understand a bit by looking, but actually writing impossible for me. Though, repping for helping me make it into an executable file. Thanks.
__________________
キャントジャパンニースのプライド!! 初音ミクの歌を聞かないけど、 彼女のキャラがズット大好きで、 可愛くてたまらないと思うんです。 Program: Profit Calculator
|
||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|