Starting Out with Programming Logic and Design (4th Edition)
4th Edition
ISBN: 9780133985078
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 5.3, Problem 5.14CP
Explanation of Solution
Purpose of the given code:
- An integer variable named counter is declared.
- A loop that iterates five times is defined.
- Display the value of counter after every iteration.
Given pseudocode:
The given code is used to display the value of counter after every iteration:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The code below is expected to count to 60 and then say time's up, why will it not perform as expected?
counter = 1
limit = 60
while counter < limit:
print(counter)
counter = counter + 1
print("Time's up")
How many times print statement below executed
for (int counter =1 counter <=10, counter ++)
{
If (counter%2==0)
Continue;
System.out.printf("%d\n", counter);
For each statement in the code, how many programming instructions are required?
Chapter 5 Solutions
Starting Out with Programming Logic and Design (4th Edition)
Ch. 5.1 - What is a repetition structure?Ch. 5.1 - What is a condition-controlled loop?Ch. 5.1 - What is a count-controlled loop?Ch. 5.2 - What is a loop iteration?Ch. 5.2 - What is the difference between a pretest loop and...Ch. 5.2 - Does the While loop test its condition before or...Ch. 5.2 - Does the Do-While loop test its condition before...Ch. 5.2 - What is an infinite loop?Ch. 5.2 - What is the difference between a Do-While loop and...Ch. 5.3 - What is a counter variable?
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 - Prob. 13PE
Knowledge Booster
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
- The instructions are on the left, the code is on the right.arrow_forwardWrite a program in assembly language so that when 5 is pressed, Sequentially ON, the LED lights and when 9 is pressed speaker beep the sound. Note: Program should be written in assembly languagearrow_forwardFinds out how many source-level instructions are needed to carry out each statement.arrow_forward
- Given this while loop below, what is wrong with it? And how to fix the error? int counter = 20; while(counter > 0) System.out.printf("%d ", counter); counter = counter + 3;arrow_forwardWrite a program to calculate the square of 20 by using a loop that adds 20 to the accumulator 20 times in assembly languagearrow_forwardanswer with proper explanation and step by step solution. Question The programmer intended the following pseudocode to display the numbers 1 through 60, and then display the message “Time’s up!” It will not function as intended, however. Find the error. Declare Integer counter = 1 Const Integer TIME_LIMIT = 60 While counter < TIME_LIMIT Display counter Set counter = counter + 1 End While Display “Time’s up!”arrow_forward
- The instructions in a loop may or may not be executed at all, while the instructions in a loop are always processed once or more.arrow_forwardWRITE THE PROGRAM IN ASSEMBLY LANGUAGE USING LC-3 STIMULATOR ALL THE METHODS SHOULD BE WRITTEN IN SUBROUTINES ONLY Modify the Calculator program to include the following functions. 1. Display a menu of the following options at startup Enter a 1 to 3 digit integer for push D - pop and display top element P - display top element but do not pop (Peek subroutine Print the top element to the console but do not pop it.If empty, display message indicating empty stack.) L - print all elements on the stack without any pop (List subroutine Print all elements on the stack to console. Do not pop any elements.) H - display number of elements currently on the stack (Height subroutine Display the number of elements on the stack as an integer. Include "N elements on the stack" output.) C - clear stack X - Halt M - display menu + - pop top two elements, add them, push result - - negate the top element * - multiply top two elements and push resultarrow_forwardWrite pseudo code and design flowchart that reads two numbers and multiplies them together and print out their product.arrow_forward
- Using Python programming language, create a PARALLEL CIRCUIT program. Input: 1 voltage source Number of resistors Value of each resistor Output: Display total current and display each current of each resistor. Example: Voltage value (V): 12 Number of resistors: 2 Resistor 1 value (ohm): 5 Resistor 2 value (ohm): 8 Total current is 3.9 A Resistor 1 current is 2.4 A Resistor 2 current is 1.5 Aarrow_forwardTake a four-digit number. Add the first two digits to the last two digits. Now, square the sum. Surprise, you have got the original number again. Of course, not all four-digit numbers have this property. Write a C program to find three numbers that have this special property and display those numbers on 7-segment LEDS for at least 2 seconds. *USE C PROGRAMNG FOR MICROPROCESSOR*arrow_forwardDraw a flowchart and write pseudocode (in python) to represent the logic of a program that allows the user to enter a value for one edge of a cube. The program calculates the surface area of one side of the cube, the surface area of the cube, and its volume. The program outputs all the results.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning