Cole H.

asked • 05/23/20

Psuedeocode Question Help

In psuedeocode suppose you want to compute the average weight of a group of items. To do this, initialize cumulativeWeight to 0, count to 0, and more to ‘y’. Then enter a loop that repeats while more equals ‘y’. Just before the end of this loop include a prompt asking “more? (y/n): ” and input the user’s answer. Inside this (outer) loop, increment count and print it out to tell the user the number of the next item. Then preset the input variable to some unacceptable value. For example, set weight to 1, and enter a second (inner) loop that repeats while weight is less than or equal to 0. In the inner loop, print “Enter kg weight greater than zero: ” and then input a value for the weight. This inner loop should automatically repeat until the input is valid. After this inner loop terminates, add the (valid) input to cumulativeWeight. After an ‘n’ input for more terminates the outer loop, compute the average by setting weight to cumulativeWeight / count, and print it out. Here is a typical interactive display:


Sample session:

Item number 1:

Enter kg weight (greater than zero): 1.23

more? (y/n): y

Item number 2:

Enter kg weight (greater than zero): 2.78

more? (y/n): y

Item number 3:

Enter kg weight (greater than zero): -0.95

Enter kg weight (greater than zero): 0.95

more? (y/n): n

Average weight = 1.6533333333333333 kg


1 Expert Answer

By:

Patrick B. answered • 05/23/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.