Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3.2, Problem 5STE
What output will be produced by the following code, when embedded in a complete
int x = 2;
cout << “Start\n”;
if (x <= 3)
if (x ! = 0)
cout << “Hello from the second if.\n”;
else
cout << “Hello from the else.\n”;
cout << “End\n”;
cout << “Start again\n”;
if (x > 3)
if (x ! = 0)
cout << “Hello from the second if.\n”;
else
cout << “Hello from the else.\n”;
cout << “End again\n”;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
8. Find the output.
b1 = True
b2 = False
b3 = False
if b1 or b2 and b3:
print ("Hello!")
else:
print ("User")
Print "user_num1 is negative." if user_num1 is less than 0. End with newline. Assign user_num2 with 1 if user_num2 is greater than 12. Otherwise, print "user_num2 is less than or equal to 12.". End with newline.
My code:
user_num1 = int(input())user_num2 = int(input())
if user_num1 < 0: print("user_num1 is negative.")
if user_num2 > 12: user_num2 == 1
else: print("user_num2 is less than or equal to 12.") print('user_num2 is', user_num2)
When the input is 0 and 13 my output for user_num2 is 13 and it should be 1. I don't know what I'm doing wrong.
options same for each one
Chapter 3 Solutions
Problem Solving with C++ (10th 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...Ch. 3 - You have an augmented reality game in which you...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Open the clock-display project and create a ClockDisplay object by selecting the following constructor: new Clo...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
What would be the output in Self-Test Exercise 5 if the assignment were changed to the following? intextra=37;
Absolute Java (6th Edition)
A new class of objects can be created conveniently bythe new class (called the subclass) starts with the charac...
Java How To Program (Early Objects)
What is the total serial transfer time for the eight bits in Figure 1-62? What is the total parallel transfer t...
Digital Fundamentals (11th 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
- int const MULTIPLIER = 5; is a valid way to declare a constant integer variable. Group of answer choices True False ------- Given the following code segment, what is output to the screen? int num1 = 6; int num2 = 4 * num1++; cout << "num1=" << num1 << " num2=" << num2; Group of answer choices num1=7 num2=24 num1=6 num2=24 num1=6 num2=28 Nothing, because the code does not compile.arrow_forwardThe Café Noir Coffee Shop wants some market research on its customers. When a customer places an order, a clerk asks for the customer’s zip code and age. The clerk enters that data as well as the number of items the customer orders. The program operates continuously until the clerk enters a 0 for zip code at the end of the day. When the clerk enters an invalid zip code (more than 5 digits) or an invalid age (defined as less than 10 or more than 110), the program reprompts the clerk continuously. When the clerk enters fewer than 1 or more than 12 items, the program reprompts the clerk two more times. If the clerk enters a high value on the third attempt, the program accepts the high value, but if the clerk enters a negative value onthe third attempt, an error message is displayed and the order is not counted. At the end of the program, display a count of the number of items ordered by customers from the same zip code as the coffee shop (54984), and a count from other zip codes. Also…arrow_forwardGiven the snippet of code: int al = {2, 4, 6, 8, 10, 12), x, *p = a; x = *(p + 4)+1; printf("%d", x); What will be the value of x after the following statement is executed? 13 5 12 11arrow_forward
- Write TRUE if the output of the expression is true and FALSE if the output of the expression is false.arrow_forwardIn this game computer chooses a random integer number, and user should guess what is that number through a trial process. You should develop a Java program to conduct this game. The Guessing Game Specification: 1- User specifies a range (from 0 to an upper band) for the game. 2- Program will generate an integer number within the above range as the game answer. 3- Program asks user to enter a guess by printing "Enter a guess" in the console. 4- After user enters a guess: o if the guess is correct, print "Correct! Took 7 guesses to find the answer.", where 7 is the number of guesses as an example. The program should then terminate. o if the guess is greater than the correct value, print "Guess is higher than the answer.". Likewise, for if the guess is less than the correct value. 5- Develop the code based on the provided sample result below. whole code should be within the main method of the Guessing Game01 class. Note: For random integer generation, you should use nextInt() method from…arrow_forwardQUESTION 15 Analyze the code and answer the questions that follow: int value = 1; do { System.out.printf("%n%d", value); System.out.printf("%nEnter a positive value or -1 to exit: "); value = keyboard.nextInt(); }while (value > -1); //END do..while 1) The sentinel value is 2) After -1 is entered at the prompt, the loop will iterate more time(s).arrow_forward
- What will be the value of x after the following code is executed? int x = 0; while (x < 50) { x += 20; } 50 20 40 60arrow_forwardAnalyze the following code: int x = 0;if (x > 0) ;{System.out.println(x);} The code has syntax error. The code has run time error. The value of variable x is always printed because the print statement is not controlled by the if condition. Nothing is printed because x > 0 is false if x = 0.arrow_forwardNeed help coding in Java Morgan’s Department Store distributes bonuses to its salespeople after the holiday rush. Table 9-6 shows the bonuses, which are based on full weeks worked during the season and the number of positive online customer reviews. Write a program that allows a user to continuously enter values for the number of weeks worked and the number of positive reviews received and displays the appropriate bonus until the user enter a sentinel value: 99.arrow_forward
- а. int GreaterThan(int no) { if (no > 10) printf("%d is greater than 10", no); else printf("%d is less than 10", no); }arrow_forwardPROBLEM: Write a program that prompts the user to input first name, middle initial, and last name (in upper case) for an ID card. There is a 22-character limit that also includes spaces in between the names on the ID card. The following conditions/limitations are observed: A. If the first name, second name, middle initial, and last name exceed the character limit, use the first name initial and last name. B. If the last name's character count is greater than or equal to the character limit, omit the second name and middle initial. Use the first name initial and truncate the last name to fit the character limit. C. The spaces in between the first name, second name, middle initial, and last name should not be included in the input. D. If there is no second name or middle initial, input 0. E. Omit any space in the last name, e.g., DE GUZMAN will be DEGUZMAN. SPECIFICATIONS: - You may only use the codes that we studied under our lectures - All lines of codes should have a comment. - Save…arrow_forward1. Write a program that does the following: Ask the user to enter the price of their items. The user can enter as many items as they want until the user enters the integer 0. Print out the total of their checkout. If the sum is greater than $100, print out "That's expensive!" Sample run of program: Enter the price of an item: > 27 Enter the price of an item: > 80 Enter the price of an item: > 0 Your checkout total is $107. That's expensive!arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY