Nerock Posted October 18, 2012 Share Posted October 18, 2012 Hi Everyone i am completely new to PHP and im not sure how to create a calculator here is the question. " First, you need the most recent three scores for the Freegumpher. You are just the statistician here, you’ll need to ask the Freegumpher to tell you the scores. (Of course, you will trust the Freegumpher to tell the truth, because Freegumphers always tell the truth.) It is possible that a Freegumpher for whom you are calculating a handicap has not played Freegumph three times in his/her life. In that case, you will just tell him/her that you cannot determine a handicap. On the other hand, some Freegumphers will be able to provide their three most recent scores. Then your job is to add them up and determine the average (mean) of the three scores. Once you have determined the average of the three scores, you have to determine the handicap. To do this, you need to compare the average to the official par for Freegumph, as provided by the National Inter-Collegiate Freegumph Society (NICFS), pronounced just like it looks. It turns out that par for Freegumph is exactly twenty-seven. If the Freegumpher’s average is higher than or equal to par, then you don’t have to do any more arithmetic – the Freegumpher’s handicap is automatically zero. On the other hand, if the Freegumpher you are currently working on has an average below the par value, you must determine the difference between the Freegumpher’s average and par (by subtracting the Freegumpher’s average from par – this will always result in a positive number.) Then you have to multiply that difference by an adjustment factor of seven/tenths. The result of that multiplication is the Freegumpher’s handicap. and here is my code any help would be greatly appreciated. when I press the get handicap button nothing happens <HTML> <HEAD> <TITLE>My Freegumph Handicap Calculator </TITLE> </HEAD> <BODY bgcolor="Green"> <?php if ($submit) { if (($one == "") || ($two =="") || ($three =="") || (!$calc)) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Oops, you forgot to supply some information. Please correct the problem below.</b></font><br>"); } else if ((!ereg("[0-9]",$one)) || (!ereg("[0-9]",$two) || (!ereg("[0-9]",$three)))) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to only numbers.</b></font><br>"); } else { $par = 0;[/size][/font][/color] [color=#000000][font=verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif][size=3] if ($calc == "Freegumph Handicap") { $total = $one + $two + $three ; $average = $total / 3 ;[/size][/font][/color] [color=#000000][font=verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif][size=3] if ( $average >= 27 ) { echo "There is no handicap you're too good!!!<br />"; } else { $par = 27 - $average; } $handicap = $par * .7; } } printf("The handicap is: <b> %.2f", $handicap . "<br>"); } ?> <FORM METHOD="post" ACTION="Freegumph.php"> <P><font face="Tahoma" size="2"><b>Enter your First Score: <br><INPUT TYPE="text" NAME="one" SIZE=20></b></font></p> <font face="Tahoma" size="2"><b>Enter your Second score: <br><INPUT TYPE="text" NAME="two" SIZE=20></b></font></p> <font face="Tahoma" size="2"><b>Enter your Third Score: <br><INPUT TYPE="text" NAME="three" SIZE=20></b></font></p> <font face="Tahoma" size="2"> <input TYPE="radio" NAME="calc" VALUE="Freegumph Handicap">Freegumph Handicap </b></font><br><br> <P><INPUT TYPE="submit" NAME="submit" VALUE="Get Handicap"></p> </FORM> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/ Share on other sites More sharing options...
Pikachu2000 Posted October 18, 2012 Share Posted October 18, 2012 Turn on error reporting. In your php.ini file, find the error_reporting and display_errors values and change them to display_errors = On error_reporting = -1 Then restart Apache, and post the errors that are generated. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1385913 Share on other sites More sharing options...
Nerock Posted October 18, 2012 Author Share Posted October 18, 2012 (edited) Sorry to sound like a complete new guy here but i have no idea what apache is my professor basically threw me a bone and said do this and if you can do it then good job, you'll be a good programmer... also heres the website i need to upload it to if that helps any... http://athena.ecs.csus.edu/~cs010130/Freegumph.php Edited October 18, 2012 by Nerock Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1385915 Share on other sites More sharing options...
gizmola Posted October 19, 2012 Share Posted October 19, 2012 The top of your script instead of having if ($submit) you need something like this: if (isset($_POST['submit']) { This is the reason that your code currently seems to do nothing -- it never reaches the computation portion because $submit is not set to anything. When you do a form post php makes the values of the form available in the $_POST superglobal. Please read up on that to understand more. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386219 Share on other sites More sharing options...
Nerock Posted October 19, 2012 Author Share Posted October 19, 2012 Yeah, that did the trick thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386232 Share on other sites More sharing options...
ManiacDan Posted October 19, 2012 Share Posted October 19, 2012 If that was the only change you needed, your classes is YEARS behind modern PHP and you shouldn't be learning from this person, bone-throwing or not. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386297 Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2012 Share Posted October 19, 2012 I notice your professor didn't say if you can get a bunch of strangers on the internet to tell you what's wrong with the code, you'll be a great programmer. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386335 Share on other sites More sharing options...
mikosiko Posted October 19, 2012 Share Posted October 19, 2012 +1 ... and unless you are using an old PHP version you should know that ereg has been already deprecated http://php.net/manual/en/function.ereg.php read the Notes for alternatives Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386357 Share on other sites More sharing options...
Nerock Posted October 20, 2012 Author Share Posted October 20, 2012 well you gotta start somewhere right? I dont think we're even learning how to program at this point we're basically just doing flow charts and learning what pseudocode is... see i dont even know what ereg is.... like i said i was basically doing this blind folded... anyone care to explain? Doesnt have to be a great explanation im just trying to learn here. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386519 Share on other sites More sharing options...
Christian F. Posted October 20, 2012 Share Posted October 20, 2012 The PHP manual contains some very good explanations for most things PHP, and I highly recommend reading through it at least once. At least up to, and later on, including the section about classes. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386553 Share on other sites More sharing options...
Nerock Posted October 20, 2012 Author Share Posted October 20, 2012 Cool, thanks! ill check that out. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386555 Share on other sites More sharing options...
ManiacDan Posted October 22, 2012 Share Posted October 22, 2012 well you gotta start somewhere right?When teaching someone English, don't start with how it was in the 15th century. Start with today. You're learning PHP so out of date it's actually dangerous and won't work on a modern web host. As for ereg: It's a family of functions which has been entirely replaced by the preg family of functions. Ereg is simply old, vestigial, deprecated functionality, left in the language for just a few more years to give out-of-date developers a final chance at updating their code. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1386871 Share on other sites More sharing options...
gizmola Posted October 23, 2012 Share Posted October 23, 2012 Everything Dan stated is completely right. However, at the end of the day, the main point of using the ereg or preg functions is to perform pattern matching against strings using regular expressions. Regex is just so damn nifty and useful for text pattern matching, that there are regex libraries for just about every language. There are a number of really good books out there on regex, but there are also some great online resources like www.regular-expressions.info. Quote Link to comment https://forums.phpfreaks.com/topic/269608-php-newbie-trying-to-make-calculator/#findComment-1387131 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.