Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. echo "Test #{$index}: {determineGrade($grades[$index])}.n";
  2.  
  3. for($index = 1; $index <= 5; $index++)
  4. {
  5. echo "Enter Test Score #{$index}:";
  6. $grades[$index] = trim(intval(fgets(STDIN)));
  7. }
  8. echo "nn ==== Results: =====n";
  9.  
  10. for($index =1; $index <= 5; $index++)
  11. {
  12. echo "Test #{$index}: {determineGrade($grades[$index])}.n";
  13. }
  14.  
  15. $average = calcAverage($grades);
  16.  
  17. function calcAverage($gradesArray)
  18. {
  19. // initialize a variable to hold the sum, calculated in loop
  20. $sumTotal = 0;
  21. // start this loop at $index=1 for consistency. Sum the grades.
  22. for($index=1; $index <= count($gradesArray); $index++)
  23. {
  24. $sumTotal = $sumTotal + $gradesArray[$index];
  25. }
  26.  
  27. return $sumTotal / 5;
  28. }
  29.  
  30. function determineGrade($gradeToDetermine)
  31. {
  32. if($gradeToDetermine >= 90)
  33. {
  34. return "A";
  35. } else if($gradeToDetermine >= 80)
  36. {
  37. return "B";
  38. }
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement