Nerock Posted November 8, 2012 Share Posted November 8, 2012 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270446-php-calcuator-cant-find-error-keeps-giving-me-same-output/ Share on other sites More sharing options...
gristoi Posted November 8, 2012 Share Posted November 8, 2012 well 3 is less than 100. so it will always stop there. u should use logic like if result is > 93 and <= 100 then its an A+ else if result is > 88 and <=93 its an A Quote Link to comment https://forums.phpfreaks.com/topic/270446-php-calcuator-cant-find-error-keeps-giving-me-same-output/#findComment-1391041 Share on other sites More sharing options...
White_Lily Posted November 8, 2012 Share Posted November 8, 2012 A+ = $FinalGrade > 93 A = $FinalGrade > 88 || <= 93 etc etc, however: F = $FinalGrade < 49 Quote Link to comment https://forums.phpfreaks.com/topic/270446-php-calcuator-cant-find-error-keeps-giving-me-same-output/#findComment-1391075 Share on other sites More sharing options...
Barand Posted November 8, 2012 Share Posted November 8, 2012 do the checks in the reverse order starting with < 49 . Quote Link to comment https://forums.phpfreaks.com/topic/270446-php-calcuator-cant-find-error-keeps-giving-me-same-output/#findComment-1391098 Share on other sites More sharing options...
Nerock Posted November 9, 2012 Author Share Posted November 9, 2012 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"); Quote Link to comment https://forums.phpfreaks.com/topic/270446-php-calcuator-cant-find-error-keeps-giving-me-same-output/#findComment-1391239 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.