Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo "Test #{$index}: {determineGrade($grades[$index])}.n";
- for($index = 1; $index <= 5; $index++)
- {
- echo "Enter Test Score #{$index}:";
- $grades[$index] = trim(intval(fgets(STDIN)));
- }
- echo "nn ==== Results: =====n";
- for($index =1; $index <= 5; $index++)
- {
- echo "Test #{$index}: {determineGrade($grades[$index])}.n";
- }
- $average = calcAverage($grades);
- function calcAverage($gradesArray)
- {
- // initialize a variable to hold the sum, calculated in loop
- $sumTotal = 0;
- // start this loop at $index=1 for consistency. Sum the grades.
- for($index=1; $index <= count($gradesArray); $index++)
- {
- $sumTotal = $sumTotal + $gradesArray[$index];
- }
- return $sumTotal / 5;
- }
- function determineGrade($gradeToDetermine)
- {
- if($gradeToDetermine >= 90)
- {
- return "A";
- } else if($gradeToDetermine >= 80)
- {
- return "B";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement