STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.12, Problem 4.38CP
What is wrong with the following switch statement?
switch (temp)
{
case temp < 0 : cout << "Temp is negative. \n";
break;
case temp == 0: cout << "Temp is zero. \n";
break;
case temp > 0 : cout << "Temp is positive. \n";
break;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given x = 4; and y = 2; and operator = '-' ; what is the final value of x after the following switch statement is executed?
switch (operator) {
case '+' : x +=y ; break ;
case '-' : x -= y ; break ; x += y ; is x = x + y ;
case '*' : x *= y ; break ;
case '/' : x /= y ; break ;
default : break ;
also,
using x = 4 ; and y = 2 ; and operator = ' * '. What is the final value of x?
}
Given x = 4; and y = 2; and operator = " ;
%3D
%3D
what is the final value of x after the
following switch statement is executed?
switch (operator) {
case '+': x +=y; break;
case - : x-= y; break;
X += y; is x = x + y ;
case *' : x *= y; break;
case '/' : x/= y; break;
default : break;
Similarly to question in number 2, using
X = 4 ; and y = 2; and operator ='*'.
%3D
What is the final value of x?
Analyze the following fragment:
double x = 0;
double d = 1;
switch (d + 4) {
case 5: x++;
case 6: --x;
}
The required default keyword is missing in the switch statement.
The switch control variable cannot be double.
The required break keyword is missing in the switch statement.
d + 4 should be replaced by 5.
Chapter 4 Solutions
STARTING OUT WITH C++ MPL
Ch. 4.1 - Prob. 4.1CPCh. 4.1 - Indicate whether each of the following statements...Ch. 4.1 - Prob. 4.3CPCh. 4.1 - What will the following program segment display?...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - Write an if statement that multiplies payRate by...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - TRUE or FALSE: Both of the following if statements...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - Write an if statement that prints The performance...
Ch. 4.2 - Although the following code segments are...Ch. 4.3 - Write an if/else statement that assigns 0.10 to...Ch. 4.3 - Write an if / else statement that assigns 1 to x...Ch. 4.3 - Write an if /else statement that assigns .10 to...Ch. 4.3 - True or false: The following if / else statements...Ch. 4.3 - Will the if / else statement shown on the right...Ch. 4.4 - What will the following program segment display?...Ch. 4.4 - The following program is used in a bookstore to...Ch. 4.4 - Write an if/else if statement that carries out the...Ch. 4.4 - Write an if/else if statement that performs the...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.7 - Prob. 4.23CPCh. 4.7 - If a = 2, b = 4, and c = 6, indicate whether each...Ch. 4.7 - If a = 2, b = 4, and c = 6, is the following...Ch. 4.7 - Rewrite the following using the ! operator so that...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Find and fix the errors in the following code...Ch. 4.10 - Prob. 4.30CPCh. 4.10 - Indicate whether each of the following relational...Ch. 4.10 - Prob. 4.32CPCh. 4.10 - Indicate whether each of these character testing...Ch. 4.11 - Rewrite the following if / else statements as...Ch. 4.11 - Rewrite the following conditional expressions as...Ch. 4.11 - Prob. 4.36CPCh. 4.12 - Explain why you cannot convert the following i...Ch. 4.12 - What is wrong with the following switch statement?...Ch. 4.12 - What will the following program segment display?...Ch. 4.12 - Complete the following program segment by writing...Ch. 4.12 - Rewrite the following program segment using a...Ch. 4.13 - Prob. 4.42CPCh. 4.13 - Follow the instructions to complete the following...Ch. 4 - An expression using the greater-than, less-than,...Ch. 4 - Prob. 2RQECh. 4 - The if statement regards an expression with the...Ch. 4 - For an if statement to conditionally execute a...Ch. 4 - In an if / else statement, the if part executes...Ch. 4 - The trailing else in an if / else if statement has...Ch. 4 - If the subexpression on the left of the logical...Ch. 4 - If the subexpression on the left of the || logical...Ch. 4 - The ____ logical operator has higher precedence...Ch. 4 - Logical operators have _____ precedence than...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - A variable with _____ scope is only visible when...Ch. 4 - The expression that is tested by a switch...Ch. 4 - A program will fall through to the following case...Ch. 4 - Prob. 16RQECh. 4 - Write an if statement that assigns 100 to x when y...Ch. 4 - Write an if/else statement that assigns 0 to x...Ch. 4 - Write an if / else statement that prints Excellent...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Convert the following conditional expression into...Ch. 4 - Convert the following if/else if statement into a...Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 26RQECh. 4 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 28RQECh. 4 - Using the following chart, write a C++ statement...Ch. 4 - Write one or more C++ statements that assign the...Ch. 4 - The following statement should determine if x is...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if x has...Ch. 4 - Each of the following program segments has errors....Ch. 4 - Sometimes either a switch statement or an if /else...Ch. 4 - Minimum / Maximum Write a program that asks the...Ch. 4 - Roman Numeral Converter Write a program that asks...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Areas of Rectangles The area of a rectangle is the...Ch. 4 - Book Club Points An online book club awards points...Ch. 4 - Change for a Dollar Game Create a change -counting...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - Math Tutor Version 2 This is a modification of the...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - Bank Charges A bank charges 15 per month plus the...Ch. 4 - Prob. 11PCCh. 4 - Color Mixer The colors red, blue, and yellow are...Ch. 4 - Running the Race Write a program that asks for the...Ch. 4 - Personal Best Write a program that asks for the...Ch. 4 - February Days The month of February normally has...Ch. 4 - Body Mass Index Write a program that calculates...Ch. 4 - Fat Gram Calculator Write a program that asks for...Ch. 4 - Prob. 18PCCh. 4 - The Speed of Sound in Gases When traveling through...Ch. 4 - Spectral Analysis If a scientist knows the...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Mobile Service Provider A mobile phone service has...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Mass and Weight Scientists measure an objects mass in kilograms and its weight in newtons. If you know the amou...
Starting Out With Visual Basic (7th Edition)
What does the following code print? System.out.printf("%s%n%s%n%s%n", "", "", "");
Java How To Program (Early Objects)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction to Programming Using Visual Basic (10th Edition)
What populates the Smalltalk world?
Concepts of Programming Languages (11th Edition)
What are some features of specific programming languages you know whose rationales are a mystery to you?
Concepts Of Programming Languages
In code, how do you make a CheckBox appear selected?
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
- switch (i){case 1:printf(" Case1 "); break;case 2:printf(" Case2 "); break;case 3:printf(" Case3 "); break;case 4:printf(" Case4 "); break;default:printf(" Default ");arrow_forwardWhat is y after the following switch statement is executed? int x = 1; int y = 3; switch (x-1) { case 1: y = 1; break; case 2: y = 2; break; default: y += 0; } 1 3 2 0arrow_forwardWhat is y after the following switch statement is executed? int x = 1; int y = 4;switch (x) {case 1: y = 1;case 2: y = 2; break;default: y += 1;} 3 4 1 2arrow_forward
- Rewrite the following code segment using if-else statement instead of switch statement: switch (i) { case 1: printf(" Casel "); break; case 2: printf(" Case2 "); break; case 3: printf(" Case3 "); break; case 4: printf(" Case4 "); break; default: printf(" Default "); } Rewrite the following code segment using switch statement instead of if-else statement: if (operator == '+' C = A+B; else if (operator == - ') C = A-B; else if (operator == *') с = A*B; else if (operator == '/') C = A/B; else error = true;arrow_forwardQ1. * Which two of the following switch statements have the same behavior? int x; cin>>x; switch (x) { a) b) c) d) O O case 1: cout>x; switch (x) { case 1: cout>x; switch (x) { } case 2: cout>x; switch (x) { case 1: case 2: cout<<"x is 1 "; cout<<"x is 2 "; break; default: cout<<"value of x unknown"; a) and b) b) and c) a) and d) c) and d) None of themarrow_forwardRemaining Time: 1 hour, 13 minutes, 36 seconds. v Ouestion Completion Status: System.out.println( --b != a); switch (0) { case 0: x = 1; case 1: x = 7; break; default: x=5; System.out.println("x = x) ; TTT Arial 3 (12pt) v T-E ill EN TOSHIBA 5L4 60arrow_forward
- A mail-order house sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; prod- uct 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the pro- gram should stop looping and display the final results.arrow_forward9. What is the value of x after the following statements are executed? int x = 5; switch (x) { case 5: } a. 6 b. 7 c. 8 x = x + 2; case 6: x = x + 1; break; default: x = x * 2; break; d. e. 10 16arrow_forward1. Write any two differences between if-else and switch statement. if-else switcharrow_forward
- while (*psz_2 != 0) {;u8_c = *psz_2;;if (u8_c > 0x2F) {;*psz_1 = u8_c | 0x20;;} else {;*psz_1 = u8_c;;}arrow_forwardVALID or INVALID. 1. #define PI 3.1416; 2. if(n1='A') 3. Do _4. case(1) 5. N*=1; _6. clrscr(); _7. #include ; _8. return 0; 9. switch(a); 10. n = n+1;arrow_forwardDetermine whether the following is valid switch statement. If not, explain why. Assume that n is an int variable. switch(n % 6){case 1:case 2:case 3:case 4:case 5:cout << n;break;case 0:cout << endl;break;}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,
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY