Jump to content

Search the Community

Showing results for tags 'calculator'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 7 results

  1. Hello All, I'm a student currently enrolled in a PHP course, and our instructor has told us to create code that would accept a users birthday and then calculate how many days from today is their next birthday. The program returns a value, but the value is incorrect. I should never receive a value over 365 days. Example: Input: 04/11/1985 Today's Date is 11/9/2016 Output (should be): "You have 153 days until your next Birthday" Actual Output: "You have 212 days until your next Birthday" What did I do wrong? Thanks in advance for any assistance Michelle <?php $johnsBirthday = $_GET ['JohnBday']; $jakesBirthday = $_GET ['JakeBday']; $john_bday = new DateTime($_GET['JohnBday']); $jake_bday = new DateTime($_GET['JakeBday']); $today_date = new DateTime(); switch (true) { case ($john_bday < $today_date) : $today_date->setDate($john_bday->format('Y'), $today_date->format('m'), $today_date->format('d')); break; case ($today_date < $john_bday) : $john_bday->setDate($today_date->format('Y'), $john_bday->format('m'), $john_bday->format('d')); break; } switch (true) { case ($today_date < $jake_bday) : $jake_bday->setDate($today_date->format('Y'), $jake_bday->format('m'), $jake_bday->format('d')); break; case ($jake_bday < $today_date) : $jake_bday->setDate($today_date->format('Y'), $jake_bday->format('m'), $jake_bday->format('d')); break; } $john_interval = $john_bday->diff($today_date); $john_diff = $john_interval->format('%a'); echo "John you have $john_diff days until your next Birthday</br>"; $jake_interval = $jake_bday->diff($today_date); $jake_diff = $jake_interval->format('%a'); echo "Jake you have $jake_diff days until your next Birthday</br>"; if ($johnsBirthday < $jakesBirthday) { echo "John is older than Jake</br>"; } elseif ($johnsBirthday > $jakesBirthday) { echo "Jake is older than John</br>"; } else { echo "Jake and John are twins"; } ?>
  2. Hello fellow coders I am having an issue coding a php calculator. My objective is to make it so that text changes depending on the operation chosen, and the answer is in the text box. if you dont input an answer, it will give you the right answer. here is how the website is supposed to act:http://usefullittlethings.com/static/index_done.php here is my code: <!DOCTYPE html> <html> <head> <title>Online Math Calculator</title> </head> <body> <h1>Thank you for trying out the online math calculator.</h1> <h2>Enter two numbers to add, subtract, multiply, or divide.</h2> <h3>If you enter the result, I will tell you if what you entered is right.</h3> If you don't enter both numbers for a formula, I will ignore it.<br /><br /> <?php $status= 'Waiting for input.<br>'; echo $status; ?> <?php function Calc(){ if (isset($a1)&&!isset($a2){ if (!empty($a1)&&!empty($a2) $a3=$a1+$a2; echo $status.'two numbers added.' } } ?> <form action="index.php" method="post"> <strong>Addition:</strong><br /> <input type="text" name="a1" value="" /> plus <input type="text" name="a2" value="" /> equals <input type="text" name="a3" value="" /> <br /><br /> <strong>Subtraction:</strong><br /> <input type="text" name="s1" value="" /> minus <input type="text" name="s2" value="" /> equals <input type="text" name="s3" value="" /> <br /><br /> <strong>Multiplication:</strong><br /> <input type="text" name="m1" value="" /> times <input type="text" name="m2" value="" /> equals <input type="text" name="m3" value="" /> <br /><br /> <strong>Division:</strong><br /> <input type="text" name="d1" value="" /> divided by <input type="text" name="d2" value="" /> equals <input type="text" name="d3" value="" /> <br /><br /> <input type="submit" value="Calculate!" /> </form> </body> </html> Thanks. Any help is appreciated!!!!!!!!!!!!!!!!!
  3. I am trying to build a calculator in PHP which uses a certain formula to come up with the results. I have a form which collects the numbers and then posts to a calc.php page which calculates the answer. Here is my HTML code <!DOCTYPE html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calculator</title> </head> <body> <form action="calc.php" method="POST"> <input type="text" name="num1"> <input type="text" name="num2"> <input type="text" name="num3"> <input type="submit" value="Calculate"> <?php echo form_close();?> </form> </body> </html> Here is my PHP but I just am missing something. <?php function calculate($num1, $num2, $num3) { $data = array() ; $data['c'] = $num1 / 50; $data['b'] = $num2 / 12; $data['s'] = $num3 / 5; $data['p'] = $data['c'] + $data['b'] - $data['s']; if($data['s'] > 4) { $data['s']= 4; } return $data ; } if (isset($_REQUEST['value'])) //Additional checks should be done tho. { $num1 = $_REQUEST["num1"]; $num2 = $_REQUEST["num2"]; $num3 = $_REQUEST["num3"]; $data = calculate($num1, $num2, $num3) ; echo "{$data['c']} + {$data['b']} - {$data['s']} = {$data['p']}" ; } Thank you for all help in advance
  4. I need to make part of my form auto-populate calculated values based on user input. Here is what I have so far: The HTML <div class="PaymentDetails"> <fieldset> <legend>Payment Details</legend> Ad Charge $ <input type="number" name="AdPrice" id="AdPrice" class="medium" value="" /><br /> Color Charge + <input type="number" name="ColorCharge" id="ColorCharge" class="medium" value="" /><br /> Web Ad + <input type="number" name="WebAd" id="WebAd" class="medium" value="" /><br /> Subtotal = <input type="number" name="AdSubtotal" id="AdSubtotal" class="medium" value=<? $SubTotal ?> /><br /> Down Payment - <input type="number" name="DownPayment" id="DownPayment" class="medium" value="" /><br /> Total = <input type="number" name="TotalPrice" id="TotalPrice" class="medium" value=<? $TotalPrice ?> /><br /><br /> # Consec. Payments \ <input type="number" name="Payments" id="Payments" class="medium" value="" /><br /> Amt Each Payment $ <input type="number" name="Payment" id="Payment" class="medium" value=<? $Payment ?> /><br /><br /> <input type="checkbox" name="ProratedCheck" id="ProratedCheck" /><label>Prorated/Length</label><input type="text" name="ProratedLength" id="ProratedLength" /> </fieldset> </div> The PHP <? $AdPrice = $_POST['AdPrice']; $ColorCharge = $_POST['ColorCharge']; $WebAd = $_POST['WebAd'] + $Number; $SubTotal = $AdPrice + $ColorCharge + $WebAd; $DownPayment = $_POST['DownPayment']; $TotalPrice = $SubTotal - $DownPayment; $Payments = $_POST['Payments']; $Payment = $TotalPrice / $Payments; ?> I know that i'm probably missing a fairly big concept here... for instance: How does the code know that a number has been entered and that a number needs to be output? Warning: Division by zero <--- i'm getting this error message also... Thank you for any help or guidance you can give!
  5. Hi, I am fairly new to using this website. I have to create a Budget tool in PHP. I am unsure of how to go about starting this though. The tool is supposed to subtract different items from a total amount. For example, subtracting rent, food, bills etc from a total amount input. This should then go about telling a user how much money they are left off at the end of their session. Any help would be much appreciated! Thank you.
  6. I made this simple shopping cart where you select quantity from a dropwdown list and these numbers get added and you get a total number for all the products and a total number for the product itself. But i want it write the quantity with price and the name and write it in a div placed on the site so that it is easy for the user to see that he added a product. I made the calculating part by adding the products one by one, as i did not array them. But for this next part i just didn't find a way that suited my needs. This is just from my test page , so i only have a few values , but in the other page i have over 70 listed just like these: <div id="radioAlert"> <script type="text/javascript"> //calculator function updatesum() { document.form.sum.value = (document.form.sum0.value -0) *99 + (document.form.sum1.value -0) *99 + (document.form.sum2.value -0) *99; document.form.smu.value = (document.form.prod0.value -0)*99 + (document.form.prod1.value -0) *99 + (document.form.prod2.value -0) *99 + (document.form.prod3.value -0) *99 + (document.form.prod4.value -0) *99; document.form.totalsum.value = (document.form.sum.value -0) + (document.form.smu.value -0); //not a typo i was just lazy with the name //arrays //This one i did not get to work. var myArray = newArray(); myArray[0]=document.form.sum2.value; myArray[1]=document.form.prod0.value; myArray[2]=document.form.prod1.value; myArray[3]=document.form.prod2.value; myArray[4]=document.form.prod3.value; myArray[5]=document.form.prod4.value; for (var i = 0; i < myArray.length; i++) { alert(myArray[i]); } //this part works but i want it to add its value only once and then replace its value if its updated again, if its 0 i want it to be completely removed. var prod1 = document.form.sum2.value; var prod2 = document.form.sum1.value; var radioAlert = document.getElementById("radioAlert"); var radioAlert2 = document.getElementById("radioAlert"); if (document.form.sum2.value>0) { //document.write("pilotjakke pelsforet small " + prod1 + " stk"); radioAlert.innerHTML += ("pilotjakke pelsforet small " + prod1 + " stk"); alert("pilotjakke pelsforet medium " + prod1 + " stk"); } if (document.form.sum1.value>0) { //document.write("pilotjakke pelsforet small " + prod1 + " stk"); radioAlert2.innerHTML += ("pilotjakke pelsforet medium " + prod2 + " stk"); } } </script> </div>
  7. somebody once told me in this forum that i can't create a good calculator with php, but i've been trying my best to prove the critics wrong, and in my effort to do so i have written a front view of how the calculator will look like but the problem is am new to php dont have an idea of how to extract the value from the clicking of a number and dont know how to go about with coding php this is the front view <table border ="5"> <table border="2"> <th><input type="text" name="num" size="23" ></th> </table> <table border="3"> <tr> <td><button size="0">+</button></td> <td><button width="0"> - </button></td> <td><button>*</button></td> <td><button>/</button></td> </tr> <tr> <td><button>-></button></td> <td><button>1</button></td> <td><button>2</button></td> <td><button>3</button></td> </tr> <tr> <td><button>4</button></td> <td><button>5</button></td> <td><button>6</button></td> <td><button>7</button></td> </tr> <tr> <td><button>8</button></td> <td><button>9</button></td> <td><button>0</button></td> <td><button>=</button></td> </tr> <tr> <td><button>.</button></td> <td><button>%</button></td> <td><button>^</button></td> <td><button>!</button></td> </tr> </table> </table> please help out
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.