Page 1 of 1

Examples/Patterns Some general patterns for calculating a running total from user input are as follows.. Each of these p

Posted: Fri Jul 01, 2022 5:51 am
by answerhappygod
Examples Patterns Some General Patterns For Calculating A Running Total From User Input Are As Follows Each Of These P 1
Examples Patterns Some General Patterns For Calculating A Running Total From User Input Are As Follows Each Of These P 1 (36.6 KiB) Viewed 50 times
Examples/PatternsSome general patterns for calculating a running total from user input are as follows.Each of these patterns has a different purpose and usage.Each algorithm pattern is described below using pseudocode.A. SentinelSENTINELtotal = 0-1get valuewhile value != SENTINELtotal = total + valueget valuedisplay totalYou would want to use a sentinel when:• you don't know how many values there will be beforehand;• there is some obvious invalid value vou can use to be the sentinel and mark the end.Note that you can use a range of invalid values, e.g., all negative numbers.E.g., calculating the average age of a line of people, where you don't know how many there are beforehand (you can use -1 for the sentinel).B. Ask-the-user-to-auit
Examples/Patterns
Some general patterns for calculating a running total from user input are as follows.
Each of these patterns has a different purpose and usage.
Each algorithm pattern is described below using pseudocode.
A. Sentinel
SENTINEL
total = 0
-1
get value
while value != SENTINEL
total = total + value
get value
display total
You would want to use a sentinel when:
• you don't know how many values there will be beforehand;
• there is some obvious invalid value vou can use to be the sentinel and mark the end.
Note that you can use a range of invalid values, e.g., all negative numbers.
E.g., calculating the average age of a line of people, where you don't know how many there are beforehand (you can use -1 for the sentinel).
B. Ask-the-user-to-auit
Examples/Patterns Some general patterns for calculating a running total from user input are as follows.. Each of these patterns has a different purpose and usage. Each algorithm pattern is described below using pseudocode. A. Sentinel to search SENTINEL=-1 total = 0 get value while value 1- SENTINEL total total value get value display total You would want to use a sentinel when • you don't know how many values there will be beforehand; • there is some obvious invalid value you can use to be the sentinel and mark the end. Note that you can use a range of invalid values, e.g, all negative numbers. Eg, calculating the average age of a line of people, where you don't know how many there are beforehand (you can use 1 for the sentinel) B. Ask the-user-to-quit O Bi