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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 49 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply