output Enter student name or QUIT to quit input name next name must be input

Output enter student name or quit to quit input name

This preview shows page 64 - 68 out of 77 pages.

output "Enter student name or ", QUIT, " to quit " input name // next name must be input endwhile stop Debug06-03 // This program counts how many sales are made // in each of five categories of products start Declarations num category num SIZE = 5 num QUIT = 9 num sales[SIZE] = 0, 0, 0, 0, 0 string HEAD1 = "Sales" string HEAD2 = "Category Number of Sales" output "Enter category ", QUIT, " to quit " input category while category <> QUIT // category must be not equal to quit if category >= 1 AND category <= SIZE then // category can be equal to 1 or SIZE and still be valid sales[category - 1] = sales[category - 1] + 1 else output "Invalid category" endif output "Enter category ", QUIT, " to quit " input category // category must be input endwhile output HEAD1 output HEAD2 category = 0 // category should start at 0 if // it is used as sales subscript while category < SIZE output category + 1, sales[category] category = category + 1 endwhile stop 2. Your downloadable files for Chapter 6 include a file named DEBUG06-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart and then find and correct all the bugs. Answer : 64
Programming Logic and Design, 8e Solutions 6- 65
Programming Logic and Design, 8e Solutions 6- Game Zone 1. Create the logic for a Magic 8 Ball game in which the user enters a question such as What does my future hold? The computer randomly selects one of eight possible vague answers, such as It remains to be seen. start Declarations num LIMIT = 8 num index string userQuestion string QUIT = “zzzz” string ANSWERS[LIMIT] = “As I see it, yes”, “It is certain”, “Signs point to yes”, 66
Programming Logic and Design, 8e Solutions 6- “It remains to be seen”, “Reply hazy, try again”, “Outlook not so good”, “Cannot predict now”, “My sources say no” getReady() while userQuestion <> QUIT detailLoop() endwhile finishUp() stop getReady() output “Enter a question or ”, QUIT, “ to quit” input userQuestion return detailLoop() index = random(LIMIT) output ANSWERS[index] output “Enter a question or ”, QUIT, “ to quit” input userQuestion return finishUp() output “End of program” return 2. Create the logic for an application that contains an array of 10 multiple-choice questions related to your favorite hobby. Each question contains three answer choices. Also create a parallel array that holds the correct answer to each question—A, B, or C. Display each question and verify that the user enters only A, B, or C as the answer —if not, keep prompting the user until a valid response is entered. If the user responds to a question correctly, display Correct!; otherwise, display The correct answer is and the letter of the correct answer. After the user answers all the questions, display the number of correct and incorrect answers. Answer: A sample solution follows Pseudocode (Please note, for brevity this solution contains only five questions.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture