An n online v ve ndor, such as a s Amazon, was colle l ec tin ng responses from those who made a purchase on the he site. Cu us tomers rated d the vendor on its se s er vic i ce and the product quality, both on a scale from 1 (worst) w to 5 5 (best). The ve v en dor used the code d sho h ow n here to collect and publish the results. When n looking over r the results, the ve en dor o r thought they did not seem correct. The calculate t ed average rati t in g should result in in an n excellent report, but only a good report was returne n ed . It turns ou ut there is a coding g erro r or . Can you find the error in their code? N No tice that the e number of each rating at g i is hard-coded into the program. This means each time the pro og ram is run with w it new data, a perso s on must m update the values. This is very time-consuming and not user-friendly. us How H would you chan ng e the th program to make it easier for users to enter new data? Coding Conundrum Program Flexibility Goodheart-Willcox Publisher Code for collecting ratings. Can you identify an error? else when clicked set to sumFives Fives * 5 set to Fives 177 set to sumFours Fours * 4 set to Fours 150 set to sumThrees Threes * 3 set to Threes 10 set to sumTwos Twos * 2 set to Twos 5 set to sumOnes Ones * 1 set to Ones 1 set to Customers + Fives + Fours + Threes + Twos Ones set to sumAllRatings + sumFives + sumFours + sumThrees + sumTwos sumOnes set to Average sumAllRatings / Customers if then Average 4 say Your customer rating is excellent! else if then Average 3 say Your customer rating is good! say You need to improve customer service. Copyright Goodheart-Willcox Co., Inc. Chapter 5 Decisions 105
Previous Page Next Page