Declare and initialize variables Input grades (prompt user and allow input) Compute class average and output resultNow, breaking down the "compute" step further, we got:
Compute: add the grades count the grades divide the sum by the countWe realized this would be a problem, because to do all input before doing the sum and the count would require us to have enough variables for all the grades (but the number of grades to be entered is not known in advance). So we revised our breakdown of "steps".
Don't be afraid to go back and revise something if the initial plan runs into a snag!
Declare and initialize variables Input grades -- count and add them as they are input Compute class average
loop until the user enters the sentinel value (-1 would be good) prompt user to enter a grade (give them needed info, like -1 to quit) allow user to type in a grade (store in a varaible) add the grade into a variable used for storing the sum add 1 to a counter (to track how many grades)We could specifically write this as a while loop or as a do-while loop. So one more refining step would be a good idea, to formulate the pseudo-code more like the actual code we would need to write. For example:
do prompt user to enter a grade (give them needed info, like -1 to quit) allow user to type in a grade (store in a varaible) add the grade into a variable used for storing the sum add 1 to a counter (to track how many grades) while user has NOT entered the sentinel value (-1 would be good)If we look at this format, we realize that the "adding" and "counting" steps should only be done if the user entry is a grade, and NOT when it's the sentinel value. So we can add one more refinement:
do prompt user to enter a grade (give them needed info, like -1 to quit) allow user to type in a grade (store in a varaible) if the entered value is a GRADE (not the sentinel value) add the grade into a variable used for storing the sum add 1 to a counter (to track how many grades) while user has NOT entered the sentinel value (-1 would be good)
This breakdown helps us see what variables are needed, so the declare and initialize variables step can be now made more specific:
initialize variables: a grade variable (to store user entry) a sum variable (initialized to 0) a counter (initialized to 0)And the compute answer and print step becomes:
divide sum by counter and store result print result
initialize variables: --------- a grade variable (to store user entry) a sum variable (initialized to 0) a counter (initialized to 0) grade entry: --------- do prompt user to enter a grade (give them needed info, like -1 to quit) allow user to type in a grade (store in a varaible) if the entered value is a GRADE (not the sentinel value) add the grade into a variable used for storing the sum add 1 to a counter (to track how many grades) while user has NOT entered the sentinel value (-1 would be good) Compute average: --------- divide the sum by the counter print the answer