# Output input first number input firstnumber output

• 38
• 100% (7) 7 out of 7 people found this document helpful

This preview shows page 33 - 37 out of 38 pages.

output "Input first number >> "input firstNumberoutput "Input second number >> "input secondNumber// secondNumber should be inputcomputeProduct(firstNumber, secondNumber)// firstNumber and secondNUmber must be passed to methodstopvoid computeProduct(num first, num second)// Method type is voidDeclarationsnum answeranswer = first * secondoutput first, "times ", second, " is ", answer// last variable output is answer, not resultreturnDEBUG09-03// Program passes an array to a method that reverses// the positions of the valuesstartDeclarationsnum LENGTH = 4num vals[LENGTH] = 33, 55, 77, 99num suboutput "At beginning of main() method..."sub = 0while sub < LENGTH// This is a loop, not a selectionoutput vals[sub]33
Programming Logic and Design, 9e
2.Your downloadable files for Chapter 9 include a file named DEBUG09-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart, and then find and correct all the bugs.
Programming Logic and Design, 9eSolutions 9-Game Zone1.In the Game Zone sections of Chapters 6 and 8, you designed the logic for a quiz that contains questions about a topic of your choice. Now, modify the program so it contains an array of five multiple-choice quiz questions related to the topic of your choice. Each question contains four answer choices. Also create a parallel array that holds the correct answer to each question—A, B, C, or D. In turn, pass each question to a method that displays the question and accepts the player’s answer. If the player does not enter a valid answer choice, force the player to reenter the choice. Return theuser’s valid (but not necessarily correct) answer to the main program. After the user’s 35
Programming Logic and Design, 9eSolutions 9-answer is returned to the main program, pass it and the correct answer to a method that determines whether the values are equal and displays an appropriate message. After the user answers all five questions, display the number of correct and incorrect answers that the user chose.Answer: A sample solution followsPseudocode:startDeclarationsnum correctnum xnum SIZE = 5string guesses[SIZE] = “”string QUESTIONS[SIZE] = “What is the closest star to Earth?”, “What is the name of Earth’s moon?”, “How many miles (in trillions) are in a light year?”, “How many moons does Pluto have?”, “What planet is the biggest?”string CHOICES[SIZE] = “A. Scopper, B. Dipper, C. Sun, D. Moon”, “A. Luna, B. Europa, C. Sol, D. Terra”, “A. 6, B. 93, C. 10, D. 35”,“A. 6, B. 2, C. 3, D. 1”, “A. Saturn, B. Jupiter, C. Earth, D. Mars”string ANSWERS[SIZE] = “C”, “A”, “A”, “C”, “B”x = 0while x < SIZEguesses[x] = getAnswer(QUESTIONS[x], CHOICES[x])correct = correct + displayAnswer(guesses[x], ANSWERS[x])x = x + 1endwhileoutput “Number of correct=”, correctoutput “Number of incorrect=”, (SIZE – correct)stopstring getAnswer(string question, string choices)Declarationsstring answeroutput questionoutput choicesinput answer
• • • 