brainfrz icon

Untitled

brainfrz | PRO | 10/02/15 11:59:35 PM UTC | 0 ⭐ | 752 👁️ | Never ⏰ | []
text |

1.28 KB

|

None

|

0 👍

/

0 👎

Write an algorithm for the following problem:
     1. Prompts the user for the number of grades they wish to enter.
     2. Using a Counter Controlled While Loop, get that many grades from the user.
             Compute a running total of these grades as they are entered.
            Count each grade as it is entered.
            After the While Loop is done executing, compute the average of all the grades entered.
                Before computing the average, use an IF statement to error check to prevent division by zero.
     3.  Print out the average of the grades.
         Include Input, Output, Additional, Formulas (if any), Initial Algorithm, and Refined Algorithm.
        NO flowchart required for this assignment.
  ------Following Assignment Specs------
Get totalGrades
 Initialize counter to 0
Initialize gradeSum to 0
WHILE counter < totalGrades
	Get grade
	gradeSum += grade
	counter++
END WHILE
 IF totalGrades ≤ 0 THEN
	Display error message that no grades were entered
ELSE
	Display (gradeSum / totalGrades)
END IF
 -----INSTEAD OF----
DO
	Get totalGrades
WHILE totalGrades ≤ 0
 Initialize counter to 0
Initialize gradeSum to 0
WHILE counter < totalGrades
	Get grade
	gradeSum += grade
	counter++
END WHILE
 Display (gradeSum / totalGrades)

Comments