Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Mistral 🤖

New Members
  • Posts

    8
  • Joined

  • Last visited

Mistral 🤖's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys, I recently posted here and I am now trying to fix the ereg because I was told it was deprecated I read some of the stuff in the php manual however I don't understand most of it since I am extremely new to programming. Here's my code, which works fine when i use the ereg function but when i use preg_match() it doesnt work it gives always give me the output "please restrict your input to numbers." However it works just fine when I use !ereg. If i enter numbers it gives me an answer and I enter letters it gives me the "please restrict your input to numbers." message. Here's the code. <HTML> <HEAD> <TITLE> Grade calculator </TITLE> </HEAD> <center><h1 style="Font-family:Vijaya;font-size:34;Color:#556B2F;"> Grade Calculator </h1></center> <BODY bgcolor="#9BCD9B"> <?php $submit = $_POST["submit"]; $Lab1 = $_POST["Lab1"]; $Lab2 = $_POST["Lab2"]; $Lab3 = $_POST["Lab3"]; $LA1 = $_POST["LA1"]; $LA2 = $_POST["LA2"]; $LA3 = $_POST["LA3"]; $LA4 = $_POST["LA4"]; $Quiz1 = $_POST["Quiz1"]; $Quiz2 = $_POST["Quiz2"]; $Quiz3 = $_POST["Quiz3"]; $Quiz4 = $_POST["Quiz4"]; $Final = $_POST["Final"]; if ($submit) { if (($Lab1 == "") || ($Lab2 =="") || ($Lab3 =="") || ($LA1 =="") || ($LA2 =="") || ($LA3 =="") || ($LA4 =="") || ($Quiz1 =="") || ($Quiz2 =="") || ($Quiz3 =="") || ($Quiz4 =="") || ($Final =="")) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>You Left an area blank, please try again.</b></font><br>"); } elseif ( ( !preg_match("[0-9]",$Lab1) ) || ( !preg_match("[0-9]",$Lab2) ) || ( !preg_match("[0-9]",$Lab3)) || ( !preg_match("[0-9]",$LA1))|| ( !preg_match("[0-9]",$LA2))|| ( !preg_match("[0-9]",$LA3)) || ( !preg_match("[0-9]",$LA4))||( !preg_match("[0-9]",$Quiz1))|| ( !preg_match("[0-9]",$Quiz2)) || ( !preg_match("[0-9]",$Quiz3))||( !preg_match("[0-9]",$Quiz4)||( !preg_match("[0-9]",$Final)))) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to numbers.</b></font><br>"); } else { $LabTotal=($Lab1 + $Lab2 + $Lab3)*(.08); $LAtotal=($LA1+$LA2+$LA3+$LA4)*(.06); $Quiztotal=($Quiz1+$Quiz2+$Quiz3+$Quiz4)*(.2); $Finalscore=($Final)*(.36); $FinalGrade=($Finalscore+$Quiztotal+$LAtotal+$LabTotal); if ($FinalGrade> 93 and $FinalGrade <=1000) { print("your grade is: " . $FinalGrade . "% " . "A"); } elseif ($FinalGrade>88 and $FinalGrade<=93) { print("your grade is: " . $FinalGrade . "% " . "A-"); } elseif ($FinalGrade>84 and $FinalGrade<=88) { print("your grade is: " . $FinalGrade . "% " . "B+"); } elseif ($FinalGrade>79 and $FinalGrade<=84) { print("your grade is: " . $FinalGrade . "% " . "B"); } elseif ($FinalGrade>76 and $FinalGrade<=79) { print("your grade is: " . $FinalGrade . "% " . "B-"); } elseif ($FinalGrade>72 and $FinalGrade <=76) { print("your grade is: " . $FinalGrade . "% " . "C+"); } elseif ($FinalGrade>69 and $FinalGrade <=72) { print("your grade is: " . $FinalGrade . "% " . "C"); } elseif ($FinalGrade>63 and $FinalGrade <=69) { print("your grade is: " . $FinalGrade . "% " . "C-"); } elseif ($FinalGrade>59 and $FinalGrade <=63) { print("your grade is: " . $FinalGrade . "% " . "D+"); } elseif ($FinalGrade>54 and $FinalGrade<=59) { print("your grade is: " . $FinalGrade . "% " . "D"); } elseif ($FinalGrade>50 and $FinalGrade<=53) { print("your grade is: " . $FinalGrade . "% " . "D-"); } elseif ($FinalGrade<49) { print("your grade is: " . $FinalGrade . "% " . "F"); } } } ?> <FORM METHOD="post" ACTION="test.php"> <P><font face="Tahoma" size="2"><b>Enter your Lab Scores: <br><INPUT TYPE="text" NAME="Lab1" SIZE=3></b></font></p> <font face="Tahoma" size="2"><b><INPUT TYPE="text" NAME="Lab2" SIZE=3></b></font></p> <font face="Tahoma" size="2"><b><INPUT TYPE="text" NAME="Lab3" SIZE=3></b></font></p> <font face="Tahoma" size="2"><b>Enter your Lecture Assignment Scores: <br><INPUT TYPE="text" NAME="LA1" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="LA2" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="LA3" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="LA4" SIZE=3></b></font></p> <font face="Tahoma" size="2"><b>Enter your Quiz Scores: <br><INPUT TYPE="text" NAME="Quiz1" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="Quiz2" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="Quiz3" SIZE=3></b></font></p> <font face="Tahoma" size="2"><INPUT TYPE="text" NAME="Quiz4" SIZE=3></b></font></p> <font face="Tahoma" size="2"><b>Enter your Final Score: <br><INPUT TYPE="text" NAME="Final" SIZE=3></b></font></p> </b></font> <P><INPUT TYPE="submit" NAME="submit" VALUE="Evaluate Grade"></p> </FORM> </BODY> </HTML> </HTML> </html>
  2. Here's what i did and it worked... Im barely learning so its probably bad but it worked... if ($FinalGrade> 93 and $FinalGrade <=1000) { print("your grade is: " . $FinalGrade . "% " . "A+"); } elseif ($FinalGrade>88 and $FinalGrade<=93) { print("your grade is: " . $FinalGrade . "% " . "A"); } elseif ($FinalGrade>84 and $FinalGrade<=88) { print("your grade is: " . $FinalGrade . "% " . "B+"); } elseif ($FinalGrade>79 and $FinalGrade<=84) { print("your grade is: " . $FinalGrade . "% " . "B"); } elseif ($FinalGrade>76 and $FinalGrade<=79) { print("your grade is: " . $FinalGrade . "% " . "B-"); } elseif ($FinalGrade>72 and $FinalGrade <=76) { print("your grade is: " . $FinalGrade . "% " . "C+"); } elseif ($FinalGrade>69 and $FinalGrade <=72) { print("your grade is: " . $FinalGrade . "% " . "C"); } elseif ($FinalGrade>63 and $FinalGrade <=69) { print("your grade is: " . $FinalGrade . "% " . "C-"); } elseif ($FinalGrade>59 and $FinalGrade <=63) { print("your grade is: " . $FinalGrade . "% " . "D+"); } elseif ($FinalGrade>54 and $FinalGrade<=59) { print("your grade is: " . $FinalGrade . "% " . "D"); } elseif ($FinalGrade>49 and $FinalGrade<=49) { print("your grade is: " . $FinalGrade . "% " . "D-"); } elseif ($FinalGrade<49) { print("your grade is: " . $FinalGrade . "% " . "F");
  3. Hey guys Im trying to make a calculator but whenever i try to display my output all it does it give me "final Grade is A+" even when the percent is 3% im not sure what im doing wrong. Could someone please help me? I would greatly appreciate it. <?php if (isset($_POST['submit'])) { $Lab1 = (isset($_POST['Lab1'])) ? $_POST['Lab1'] : ''; $Lab2 = (isset($_POST['Lab2'])) ? $_POST['Lab2'] : ''; $Lab3 = (isset($_POST['Lab3'])) ? $_POST['Lab3'] : ''; $LA1 = (isset($_POST['LA1'])) ? $_POST['LA1'] : ''; $LA2 = (isset($_POST['LA2'])) ? $_POST['LA2'] : ''; $LA3 = (isset($_POST['LA3'])) ? $_POST['LA3'] : ''; $LA4 = (isset($_POST['LA4'])) ? $_POST['LA4'] : ''; $Quiz1 = (isset($_POST['Quiz1'])) ? $_POST['Quiz1'] : ''; $Quiz2 = (isset($_POST['Quiz2'])) ? $_POST['Quiz2'] : ''; $Quiz3 = (isset($_POST['Quiz3'])) ? $_POST['Quiz3'] : ''; $Quiz4 = (isset($_POST['Quiz4'])) ? $_POST['Quiz4'] : ''; $Final = (isset($_POST['Final'])) ? $_POST['Final'] : ''; if (($Lab1 == "") || ($Lab2 =="") || ($Lab3 =="") || ($LA1 =="") || ($LA2 =="") || ($LA3 =="") || ($LA4 =="") || ($Quiz1 =="") || ($Quiz2 =="") || ($Quiz3 =="") || ($Quiz4 =="") || ($Final =="")) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>You Left an area blank, please try again.</b></font><br>"); } elseif ( ( !ereg("[0-9]",$Lab1) ) || ( !ereg("[0-9]",$Lab2) ) || ( !ereg("[0-9]",$Lab3) ) ) { echo("<font face=\"Tahoma\" size=\"2\" color=\"#FF0000\"><b>Please restrict your input to numbers.</b></font><br>"); } else { $LabTotal=($Lab1 + $Lab2 + $Lab3)*(.08); $LAtotal=($LA1+$LA2+$LA3+$LA4)*(.06); $Quiztotal=($Quiz1+$Quiz2+$Quiz3+$Quiz4)*(.2); $Finalscore=($Final)*(.36); $FinalGrade=($Finalscore+$Quiztotal+$LAtotal+$LabTotal); } } if ($finalGrade< 100) { print("your grade is: " . $FinalGrade . "% " . "A+"); } elseif ($FinalGrade<93) { print("your grade is:" . $FinalGrade . "%" . "A"); } elseif ($FinalGrade<88) { print("your grade is:" . $FinalGrade . "%" . "B+"); } elseif ($FinalGrade<84) { print("your grade is:" . $FinalGrade . "%" . "B"); } elseif ($FinalGrade<79) { print("your grade is:" . $FinalGrade . "%" . "B-"); } elseif ($FinalGrade<76) { print("your grade is:" . $FinalGrade . "%" . "C+"); } elseif ($FinalGrade<72) { print("your grade is:" . $FinalGrade . "%" . "C"); } elseif ($FinalGrade<69) { print("your grade is:" . $FinalGrade . "%" . "C-"); } elseif ($FinalGrade<63) { print("your grade is:" . $FinalGrade . "%" . "D+"); } elseif ($FinalGrade<59) { print("your grade is:" . $FinalGrade . "%" . "D"); } elseif ($FinalGrade<54) { print("your grade is:" . $FinalGrade . "%" . "D-"); } elseif ($FinalGrade<49) { print("your grade is:" . $FinalGrade . "%" . "F"); } ?>
  4. Cool, thanks! ill check that out.
  5. 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.
  6. Yeah, that did the trick thank you very much!
  7. 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
  8. 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>
×
×
  • 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.