brainfrz

Untitled

Oct 2nd, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. Write an algorithm for the following problem:
  2.  
  3. 1. Prompts the user for the number of grades they wish to enter.
  4.  
  5. 2. Using a Counter Controlled While Loop, get that many grades from the user.
  6.  
  7. Compute a running total of these grades as they are entered.
  8. Count each grade as it is entered.
  9. After the While Loop is done executing, compute the average of all the grades entered.
  10. Before computing the average, use an IF statement to error check to prevent division by zero.
  11.  
  12. 3. Print out the average of the grades.
  13.  
  14. Include Input, Output, Additional, Formulas (if any), Initial Algorithm, and Refined Algorithm.
  15. NO flowchart required for this assignment.
  16.  
  17.  
  18. ------Following Assignment Specs------
  19. Get totalGrades
  20.  
  21. Initialize counter to 0
  22. Initialize gradeSum to 0
  23. WHILE counter < totalGrades
  24. Get grade
  25. gradeSum += grade
  26. counter++
  27. END WHILE
  28.  
  29. IF totalGrades ≤ 0 THEN
  30. Display error message that no grades were entered
  31. ELSE
  32. Display (gradeSum / totalGrades)
  33. END IF
  34.  
  35. -----INSTEAD OF----
  36. DO
  37. Get totalGrades
  38. WHILE totalGrades ≤ 0
  39.  
  40. Initialize counter to 0
  41. Initialize gradeSum to 0
  42. WHILE counter < totalGrades
  43. Get grade
  44. gradeSum += grade
  45. counter++
  46. END WHILE
  47.  
  48. Display (gradeSum / totalGrades)
Advertisement
Add Comment
Please, Sign In to add comment