Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment