Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862225
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.3, Problem 29STE
Rewrite the following loops as for loops.
a. int i = 1;
while (i <= 10)
{
if (i < 5 && i != 2)
cout << ‘X’;
i++;
}
b. int i=1;
while (i <= 10)
{
cout << ‘X’;
i = i + 3;
}
c. long m = 100;
do {
cout << ‘X’;
m = m + 100;
}
while (m < 1000);
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
in java
String inputWord is read from input. Write a while loop that iterates until inputWord is equal to "Finale". In each iteration of the loop:
Read integer clothingNumber from input.
If clothingNumber is less than 30, output the value of inputWord, followed by ": low on stock" and a newline.
Otherwise, output the value of inputWord, followed by ": well stocked" and a newline.
Read string inputWord from input.
Click here for example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Scanner;
public class PairedDataProcessing {
publicstaticvoidmain(String[] args) {
Scannerscnr=newScanner(System.in);
StringinputWord;
intclothingNumber;
inputWord=scnr.next();
/* Your code goes here */
}
}
Loops, C++
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer.
Ex: If the input is:
-15 10
the output is:
-15 -10 -5 0 5 10
Ex: If the second integer is less than the first as in:
20 5
the output is:
Second integer can't be less than the first.
For coding simplicity, output a space after every integer, including the last.
write this in pseudocode
#4 – In pseudocode, write a for-loop that decreases from 100 to 2 by 2s. Inside the loop, print the value of the loop variable unless the value is from 60 to 80 (inclusive). Use only 1 if-statement. Do NOT write Python code! Write your answer below:
#5 – Review the decision structure given below. If myAnswer > 20 Then myAnswer = myAnswer - 25Else If myAnswer <= 5 Then If myAnswer < 0 Then myAnswer = 10 If myAnswer < 3 Then myAnswer += 10 Else myAnswer += 1Else myAnswer = 9 If myAnswer < 10 ThenmyAnswer += 1
Display myAnswer
What are the results displayed when the decision structure above executes for each given value below:If myAnswer = 6 then myAnswer = myAnswer = 15 then myAnswer = myAnswer = 30 then myAnswer = myAnswer = 2 then myAnswer = myAnswer = -1 then myAnswer = #6 – 2-dimensional arrays can be thought of as containing rows…
Chapter 3 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (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
State whether each of the following is true or false. A set of statements contained within a pair of parenthese...
Java How To Program (Early Objects)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Explain how entities are transformed into tables.
Database Concepts (7th Edition)
Describe the three types of anomalies that can arise in a table and the negative consequences of each.
Modern Database Management
State which values of the control variable x are printed by each of the following for statements:
C How to Program (8th Edition)
What is a constructors return type?
Starting Out with Java: Early Objects (6th 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
- With respect to the following nested loops, what is missing or wrong? int loopCount;while (loopCount <= 8){ int innerCount = 0; while (innerCount <= 7) { System.out.println('*'); innerCount++; } loopCount++;} Group of answer choices 1.the initialization of a loop control variable 2. the testing of a loop control variable 3. nothing is missing 4. the incrementation of a loop control variablearrow_forwardLoops question. Write a C program that reads an integer k from the user and then prints the multiples of 1 up to k, the multiples of 2 up to k/2, etc. For k = 10, the printout would be 1,2,3,4,5,6,7,8,9,10, 2,4,6,8,10 3,6,9 4,8 5,10,arrow_forwardWrite a guessing game program: - The program has to first generate a random number in range 1 - 100 inclusive.- The user has to enter a guess- The program has to either print lower or higher (if the user guess is less than the answer, it should print higher, otherwise lower)- The program should end and print 'You got it!' when the user gets it right. example: generated random number: 78 ````50```` example: generated random number: 78 ````50```` ````higher```` ````75```` ````higher```` ````87```` ````lower```` ````81```` ````lower```` ````78```` ````You got it!````arrow_forward
- Change the following Java for loop to a Java while loop. for ( int num=10; num>=1; num=num-2) System.out.println( num );arrow_forwardA robot is initially located at position (0, 0) in a grid [−5, 5] × [−5, 5]. The robot can move randomly in any of the directions: up, down, left, right. The robot can only move one step at a time. For each move, print the direction of the move and the current position of the robot. If the robot makes a circle, which means it moves back to the original place, print “Back to the origin!” to the console and stop the program. If it reaches the boundary of the grid, print “Hit the boundary!” to the console and stop the program. A successful run of your code may look like: Down (0,-1) Down (0,-2) Up (0,-1) Left (-1,-1) Left (-2,-1) Up (-2,0) Left (-3,0) Left (-4,0) Left (-5,0) Hit the boundary! or Left (-1,0) Down (-1,-1) Right (0,-1) Up (0,0) Back to the origin! Instructions: This program is to give you practice using the control flow, the random number generator, and output formatting. You may not use stdafx.h. Include header comments. Include <iomanip> to format your output. Name…arrow_forwardWrite a program that receives student's marks (8 marks) and evaluates the average: use conditions or loops If 50<=average<60 print "poor". If 60<=average<70 print "medium". If 70<=average<80 print "good". If 80<=average<90 print "very good". If 90<=average<=100 print "excellent". Otherwise, print "failarrow_forward
- This assignment does not exactly match the one in the textbook on which it is based. I don't want any counter-controlled loops in your solution. Your solution should be able to detect when the accuracy isn't improving and then display the results of the work (as outlined below): Look at Programming Exercise **5.25 in the textbook on approximating the value of π. It is described as: π = 4 ( 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ... + (-1)^(i+1)/(2i-1) ) Notice that Java has the best possible value of π that can be stored as a type double available as Math.PI (part of the java.lang package). See how close you can get to the best value of π using a loop with the above technique. Notice that the above implies you are testing the value of your own estimate as it approaches the best value available in Java (as a type double). This would not be a pre-determined, counter-controlled loop. You are testing the results (sentinel-controlled) until you reach a value with the minimum discrepancy…arrow_forwardAll the loops below are meant to do the same thing, except... Select one: a. int index = 0; do{ if(numbers[index]%2 == 1) System.out.println(numbers[index]+" is an odd number."); index++;}while(index < numbers.length); b. for(int a=0 ;a < numbers.length; a +=2){ System.out.println(numbers[a]+" is an odd number.") } c. for(int num:numbers){ if(num%2 == 1) System.out.println(num+" is an odd number.") } d. int index = 0; while(index < numbers.length){ if(numbers[index]%2 == 1) System.out.println(numbers[index]+" is an odd number."); index++; } CLEAR MY CHOICEarrow_forwardJAVA Program modify this program below: so it does not use a while loop. Instead it uses recursive method that doesn't copy the string over and over again. import java.util.Scanner;public class PalindromeChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.print("Please enter a string to test for palindrome or type QUIT to exit:\n"); String input = scanner.nextLine().toLowerCase(); if (input.equals("quit")) { break; } if (isPalindrome(input)) { System.out.println("The input is a palindrome."); } else { System.out.println("The input is not a palindrome."); } } } private static boolean isPalindrome(String str) { str = str.replaceAll("[^a-zA-Z0-9]", ""); int left = 0; int right = str.length() - 1; while (left < right) { if…arrow_forward
- JAVA: Replace the for loop below with a code using the "While" loop: int s = 0; int c = 0; boolean valid = true; for(int i = 4; i <= 20 || valid; i = i+2) { if(i%4 != 0) { s = s + i; c++; } if(i > 20) { valid = false; } } System.out.println(s / c);arrow_forwardWrite a program in Java using the for loop, the while loop and the do- while loop to print the numbers from 10 to 100 as follows: 10 20 30 40 50 60 70 80 90.100arrow_forwardUsing While Loop in Java Write a program that let the user include his or her three (3) grades. After inputting the three (3) grades, the program should compute and print the average. After printing the average, it should determine whether: If average score is equal or greater than 90, the program will print "A" If average score is greater than or equal to 70, and less than 90, the program will print "B" If average score is greater than or equal to 50, and less than 70, the program will print "C" If average score less than 50, the program will print "F"arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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