Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 5, Problem 3DE

The programmer intended the following pseudocode to get five sets of two numbers each, calculate the sum of each set, and calculate the sum of all the numbers entered. It will not function as intended, however. Find the error.

// This program calculates the sum of five sets of two numbers.

Declare Integer number, sum, total

Declare Integer sets, numbers

Constant Integer MAX_SETS = 5

Constant Integer MAX_NUMBERS = 2

Set sum = 0;

Set total = 0;

For sets = 1 To MAX_NUMBERS

For numbers = 1 To MAX_SETS

Display "Enter number ", numbers, " of set ", sets, "."

Input number ;

Set sum = sum + number

End For

Display "The sum of set " sets, " is , sum, "."

Set total = total + sum

Set sum = 0

End For

Display "The total of all the sets is total , "."

Blurred answer
Students have asked these similar questions
You will use sequential, selection and repetition programming statements. You will define one integer number: count count will store how many times valid weights and values have been entered. You will define a variety of doubles: weight, value, sum, sumw, avg value will store the input value weight will store the input weight for that value sum  will  store  the  running   sum  of  values  and weights sumw will store the running of the weights avg  will store  the weighted  average  of  the 5 numbers  and 5  weights  input. The running sum will be calculated by this formula: sum = sum + value * weight For  example, if   the  first value  and  weight  pair  entered  is 4, 1 and  second pair  is 10, 3: sum = sum + value*weight = 0 + 4*1 sum = 4 + 10*3 = 34 sumw = 1 + 3 = 4 Values and sum are to be input and calculated within a repetition loop: while count <  5 Input value, weight sumw = sumw + weight sum = sum + value * weight count = count + 1 End while Avg is calculated by: avg =…
You will use sequential, selection and repetition programming statements. You will define one integer number: count count will store how many times valid weights and values have been entered. You will define a variety of doubles: weight, value, sum, sumw, avg value will store the input value weight will store the input weight for that value sum  will  store  the  running   sum  of  values  and weights sumw will store the running of the weights avg  will store  the weighted  average  of  the 5 numbers  and 5  weights  input. The running sum will be calculated by this formula: sum = sum + value * weight For  example, if   the  first value  and  weight  pair  entered  is 4, 1 and  second pair  is 10, 3: sum = sum + value*weight = 0 + 4*1 sum = 4 + 10*3 = 34 sumw = 1 + 3 = 4 Values and sum are to be input and calculated within a repetition loop: while count <  5 Input value, weight sumw = sumw + weight sum = sum + value * weight count = count + 1 End while Avg is calculated by: avg =…
You will use sequential, selection and repetition programming statements. You will define one integer number: count count will store how many times valid weights and values have been entered. You will define a variety of doubles: weight, value, sum, sumw, avg value will store the input value weight will store the input weight for that value sum  will  store  the  running   sum  of  values  and weights sumw will store the running of the weights avg  will store  the weighted  average  of  the 5 numbers  and 5  weights  input. The running sum will be calculated by this formula: sum = sum + value * weight For  example, if   the  first value  and  weight  pair  entered  is 4, 1 and  second pair  is 10, 3: sum = sum + value*weight = 0 + 4*1 sum = 4 + 10*3 = 34 sumw = 1 + 3 = 4 Values and sum are to be input and calculated within a repetition loop: while count <  5 Input value, weight sumw = sumw + weight sum = sum + value * weight count = count + 1 End while Avg is calculated by: avg =…

Chapter 5 Solutions

Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)

Ch. 5.3 - What three actions do count-controlled loops...Ch. 5.3 - When you increment a variable, what are you doing?...Ch. 5.3 - Look at the following pseudocode. If it were a...Ch. 5.3 - Prob. 5.14CPCh. 5.3 - Look at the following pseudocode. If it were a...Ch. 5.3 - Look at the following pseudocode. If it were a...Ch. 5.3 - Look at the following pseudocode. If it were a...Ch. 5.3 - Look at the following pseudocode. If it were a...Ch. 5.4 - A program that calculates the total of a series of...Ch. 5.4 - Prob. 5.20CPCh. 5.4 - Should an accumulator be initialized to any...Ch. 5.4 - Look at the following pseudocode. If it were a...Ch. 5.4 - Look at the following pseudocode. If it were a...Ch. 5.5 - Prob. 5.24CPCh. 5.5 - Why should you take care to choose a unique value...Ch. 5 - A ______ controlled loop uses a true/false...Ch. 5 - A ______ controlled loop repeats a specific number...Ch. 5 - Each repetition of a loop is known as a(n) ______....Ch. 5 - The Whi1e loop is a ______ type of loop. a....Ch. 5 - The Do-Whi1e loop is a ______ type of loop. a....Ch. 5 - The For loop is a ______ type of loop. a. pretest...Ch. 5 - A(n) ______ loop has no way of ending and repeats...Ch. 5 - A _______ loop always executes at least once. a....Ch. 5 - Prob. 9MCCh. 5 - A(n) ______ is a special value that signals when...Ch. 5 - A condition-controlled loop always repeats a...Ch. 5 - The While loop is a pretest loop.Ch. 5 - The Do-While loop is a pretest loop.Ch. 5 - You should not write code that modifies the...Ch. 5 - You cannot display the contents of the counter...Ch. 5 - Prob. 6TFCh. 5 - The following statement decrements the variable x:...Ch. 5 - It is not necessary to initialize accumulator...Ch. 5 - In a nested loop, the inner loop goes through all...Ch. 5 - To calculate the total number of iterations of a...Ch. 5 - Why should you indent the statements in the body...Ch. 5 - Describe the difference between pretest loops and...Ch. 5 - What is a condition-controlled loop?Ch. 5 - What is a count-controlled loop?Ch. 5 - What three actions do count-controlled loops...Ch. 5 - What is an infinite loop? Write the code for an...Ch. 5 - A For loop looks like what other loop in a...Ch. 5 - Why is it critical that accumulator variables are...Ch. 5 - What is the advantage of using a sentinel?Ch. 5 - Prob. 10SACh. 5 - Design a Whi1e loop that lets the user enter a...Ch. 5 - Design a Do-Whi1e loop that asks the user to enter...Ch. 5 - Design a For loop that displays the following set...Ch. 5 - Design a loop that asks the user to enter a...Ch. 5 - Design a For loop that calculates the total of the...Ch. 5 - Design a nested loop that displays 10 rows of #...Ch. 5 - Convert the Whi1e loop in the following code to a...Ch. 5 - Convert the Do-Whi1e loop in the following code to...Ch. 5 - Convert the following Whi1e loop to a For loop:...Ch. 5 - Convert the following For loop to a Whi1e loop:...Ch. 5 - Find the error in the following pseudocode....Ch. 5 - The programmer intended the following pseudocode...Ch. 5 - The programmer intended the following pseudocode...Ch. 5 - Bug Collector A bug collector collects bugs every...Ch. 5 - Calories Burned Running on a particular treadmill...Ch. 5 - Budget Analysis Design a program that asks the...Ch. 5 - Sum of Numbers Design a program with a loop that...Ch. 5 - Tuition Increase At one college, the tuition for a...Ch. 5 - Distance Traveled The distance a vehicle travels...Ch. 5 - Average Rainfall Design a program that uses nested...Ch. 5 - Celsius to Fahrenheit Table Design a program that...Ch. 5 - Pennies for Pay Design a program that calculates...Ch. 5 - Largest and Smallest Design a program with a loop...Ch. 5 - First and Last Design a program that asks the user...Ch. 5 - Calculating the Factorial of a Number In...Ch. 5 - Multiplication Table Design a program that uses...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Control Structures - while loop - do-while loop - for loop - Goto - break - continue statements; Author: EzEd Channel;https://www.youtube.com/watch?v=21l11_9Osd0;License: Standard YouTube License, CC-BY