Jump to content

Php Calcuator Cant Find Error Keeps Giving Me Same Output


Recommended Posts

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");
 }
?>


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");

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.