Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3.4, Problem 37STE
Write a loop that will read in a list of even numbers (such as 2, 24, 8, 6) and compute the total of the numbers on the list. The list is ended with a sentinel value. Among other things, you must decide what would be a good sentinel value to use.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java
What the following code does? Replace the while loop with a for loop in the code:
int s=0, i=2;
while(i<=200) {
s=s+i; i=i+2;
}
Write a for loop that computes the sum of the integers from 1 to n. Get the value of n from the user.
Chapter 3 Solutions
Problem Solving with C++ (9th Edition)
Ch. 3.1 - Determine the value, true or false, of each of the...Ch. 3.1 - Name two kinds of statements in C++ that alter the...Ch. 3.1 - In college algebra we see numeric intervals given...Ch. 3.1 - Prob. 4STECh. 3.2 - What output will be produced by the following...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 9...
Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - Write a multiway if-else statement that classifies...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - Prob. 19STECh. 3.2 - Though we urge you not to program using this...Ch. 3.3 - Prob. 21STECh. 3.3 - Prob. 22STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 25STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 27STECh. 3.3 - For each of the following situations, tell which...Ch. 3.3 - Rewrite the following loops as for loops. a.int i...Ch. 3.3 - What is the output of this loop? Identify the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What does a break statement do? Where is it legal...Ch. 3.4 - Write a loop that will write the word Hello to the...Ch. 3.4 - Write a loop that will read in a list of even...Ch. 3.4 - Prob. 38STECh. 3.4 - Prob. 39STECh. 3.4 - What is an off-by-one loop error?Ch. 3.4 - You have a fence that is to be 100 meters long....Ch. 3 - Write a program to score the paper-rock-scissor...Ch. 3 - Write a program to compute the interest due, total...Ch. 3 - Write an astrology program. The user types in a...Ch. 3 - Horoscope Signs of the same Element are most...Ch. 3 - Write a program that finds and prints all of the...Ch. 3 - Buoyancy is the ability of an object to float....Ch. 3 - Write a program that finds the temperature that is...Ch. 3 - Write a program that computes the cost of a...Ch. 3 - (This Project requires that you know some basic...Ch. 3 - Write a program that accepts a year written as a...Ch. 3 - Write a program that scores a blackjack hand. In...Ch. 3 - Interest on a loan is paid on a declining balance,...Ch. 3 - The Fibonacci numbers F are defined as follows. F...Ch. 3 - The value ex can be approximated by the sum 1 + x...Ch. 3 - Prob. 8PPCh. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 13 from Chapter 2 but...Ch. 3 - The keypad on your oven is used to enter the...Ch. 3 - The game of 23 is a two-player game that begins...Ch. 3 - Holy digits Batman! The Riddler is planning his...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a loop equivalent to the for loop above without using .
C Programming Language
Fill in the blanks in each of the following statements: A decision can be made in a Java program with a(n).
Java How To Program (Early Objects)
We have defined four binary logical connectives. a. Are there any others that might be useful? b. How many bina...
Artificial Intelligence: A Modern Approach
In Exercises 3 through 24, carry out the task. In Exercises 3 through 24, carry out the task. Create a label co...
Introduction To Programming Using Visual Basic (11th Edition)
John travels a distance of 55 miles at an average speed of 15 miles per hour. Write a program to calculate the ...
Absolute Java (6th Edition)
Property Tax A county collects property taxes on the assessment value of property, which is 60 percent of the p...
Starting Out with C++ from Control Structures to Objects (9th Edition)
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
- PrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forwardWrite code that uses any type of loop. The code should continually ask for a user input and sums all user inputs that are divisible by 2. The loop should continue until the user enters a negative number. The code should output the sum a single time once user entry has completed. You may assume all libraries and namespaces have been previously written into the code, you are just writing everything that would go inside the main function (beyond the return 0:).arrow_forwardBy using while loop OR do..while loop, write a program that displays a list of groceries. Then, allow user to insert number of product that they want to buy, the item's code and quantity for each item. Finally, display the total price that the user needs to pay. Valid input for the number of product and quantity is positive number. Meanwhile valid number for items' code is only from 1 to 4. 1 Cooking oil 2 Curry powder RM 3.40 3 Detergent Potato chips RM 2.50 RM 8.50 4 RM 3.20 Sample output Emer number of product that you want to purchase (press 0 to exit) : 2 1.Enter item's code that you want to buy : 3 1.Enter the quantity of item that you want to buy: 1 2.Enter item's code that you want to buy : 0 2.Enter the quantity of item that you want to buy: 0 2.Enter item's code that you want to buy : 1 2.Enter the quantity of item that you want to buy; 2 Total price is RM 13.50arrow_forward
- What is the number of times the following loop is executed? for the value of b in (1,10): a printout of barrow_forwardDo a trace on the for loop below, and show each iteration of the loop in the tracing table until the loop finishes. Each row in the table corresponds to one iteration of the for loop. int j=3, k=2; for(int i = 12; i >7; i--){ k = k + j - - * i ; } The tracing table is here: i i > 7 j karrow_forwardFactorials The factorial of n (written n!) is the product of the integers between 1 and n. Thus 4! = 1*2*3*4 = 24. By definition, 0! = 1. Factorial is not defined for negative numbers. Write a program that asks the user for a non-negative integer and computes and prints the factorial of that integer. You'll need a while loop to do most of the work-this is a lot like computing a sum, but it's a product instead. And you'll need to think about what should happen if the user enters 0. 1. 2. Now modify your program so that it checks to see if the user entered a negative number. If so, the program should print a message saying that a nonnegative number is required and ask the user the enter another number. The program should keep doing this until the user enters a nonnegative number, after which it should compute the factorial of that number. Hint: you will need another while loop before the loop that computes the factorial. You should not need to change any of the code that computes the…arrow_forward
- Code in Java - While Loop Write a program that takes an integer and prints the number of trailing zeroes. Trailing zeroes are the zeroes found at the right side of a number.arrow_forwardWrite a program that uses a for loop to display a table that lists in one column values for ounces, followed by columns that show the equivalent in pints, quarts and litres: Enter a start value, an end value and a step value for a range of values for the ounces. • Use a for loop to do the following for the range values: • Show on each line of the table four columns starting with the ounces, followed by the pints, quarts and litres. The formulas for the units are: • pints: ounces * 0.0625 • quarts: ounces * 0.03125 • litres: ounces * 0.02957 • Show all values in the table with two decimal places each, and right-aligned so all the decimal places are lined up with one another. Use a while loop to show the table. • Show the table from a high value to a low value.arrow_forwardWrite a loop that iterates exactly ten times. With each iteration it should ask the user to enter a number, and keep a running total of all numbers entered. When the loop is finished, display the total sum (float) and the average of the 10 numbers (float).arrow_forward
- n is an integer variable.Write a while loop that prints integer numbers starting with n and dividing the number to 4 each time, while the new number is greater than 0.(Example: If n is 2077, it will print 2077 519 129 ...)Write only the statements to perform the above explained task, nothing else.Use while loop, don't use for loop.arrow_forwardWrite a for loop that displays the following set of numbers: 0, 20, 40, 60, 80,…..1000 (Note there is a comma between the numbers but not the last one)explain please.arrow_forwarda and b are int variables containing values, and a < b.Write a for loop that prints all odd numbers from a to b (both inclusive).(Example: if a=25, b=82, then it will print 25 27 29 .... 79 81)Write only the for loop with its block, nothing else. with javaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY