Starting Out With Visual C# (5th Edition)
5th Edition
ISBN: 9780135183519
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.10, Problem 4.29CP
Convert the following if-else-if code to a switch statement:
if (choice == 1)
{
MessageBox.Show("You chose 1.");
}
else if (choice == 2)
{
MessageBox.Show("You chose 2.");
}
else if (choice == 3)
{
MessageBox.Show("You chose 3.");
}
else
{
MessageBox.Show("Make another choice.");
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Rewrite the following if-else-if statement as a switch statement.if (selection == 1){ MessageBox.Show("You selected 1.");}else if (selection == 2){ MessageBox.Show("You selected 2.");}else if (selection == 3){ MessageBox.Show("You selected 3.");}else if (selection == 4){ MessageBox.Show("You selected 4.");}else{ MessageBox.Show("Not good with numbers, eh?");}
A one-way if statement performs an action if the specified condition is true. If the condition is false, nothing is done. But what if you want to take alternative actions when the condition is false?
Code Example 3-1
num_widgets = 0
while True:
choice input ("Would you like to buy a widget? (y/n): ")
if choice. lower () == "y":
num_widgets += 1
else:
break
print ("You bought", num_widgets, "widget (s).")
Refer to Code Example 3-1. If the user enters "Y" at the prompt, what does the program print to the console?
O a.
You bought 1 widget (s) today.
O b. You bought 0 widget (s) today.
O c.
You bought Y widget (s) today.
O d. Nothing, the break statement will cause the program to end
Chapter 4 Solutions
Starting Out With Visual C# (5th Edition)
Ch. 4.1 - What is a control structure?Ch. 4.1 - What is a decision structure?Ch. 4.1 - Prob. 4.3CPCh. 4.1 - Prob. 4.4CPCh. 4.1 - What types of relationships between numeric values...Ch. 4.1 - Write an if statement that determines whether the...Ch. 4.1 - Write an if statement that determines whether the...Ch. 4.2 - Prob. 4.8CPCh. 4.2 - In an if-else statement, under what circumstances...Ch. 4.2 - Write an if-else statement that works like this:...
Ch. 4.3 - Convert the following set of nested if-else...Ch. 4.4 - Prob. 4.12CPCh. 4.4 - Prob. 4.13CPCh. 4.4 - Assume the variables a = 2, b = 4, and c = 6....Ch. 4.4 - Explain how short-circuit evaluation works with...Ch. 4.4 - Write an if statement that displays the message...Ch. 4.4 - Write an if statement that displays the message...Ch. 4.5 - Prob. 4.18CPCh. 4.5 - Prob. 4.19CPCh. 4.6 - If the following code were part of a complete...Ch. 4.6 - If the following code were part of a complete...Ch. 4.7 - Prob. 4.22CPCh. 4.7 - If a TryParse method successfully converts the...Ch. 4.7 - Prob. 4.24CPCh. 4.7 - Prob. 4.25CPCh. 4.9 - Prob. 4.26CPCh. 4.9 - If several CheckBox controls have been created in...Ch. 4.9 - Prob. 4.28CPCh. 4.10 - Convert the following if-else-if code to a switch...Ch. 4.11 - Prob. 4.30CPCh. 4.11 - Prob. 4.31CPCh. 4.11 - Prob. 4.32CPCh. 4 - A __________ structure executes a set of...Ch. 4 - A __________ structure provides one alternative...Ch. 4 - A(n) __________ expression has a value of either...Ch. 4 - The symbols , , and == are all __________...Ch. 4 - A __________ structure tests a condition and then...Ch. 4 - You use a(n) __________ statement to write a...Ch. 4 - You use a(n) __________ statement to write a dual...Ch. 4 - A ____________ decision structure is written...Ch. 4 - , ||, and ! are __________ operators. a....Ch. 4 - A compound Boolean expression created with the...Ch. 4 - A compound Boolean expression created with the...Ch. 4 - The __________ operator takes a Boolean expression...Ch. 4 - A __________ is a Boolean variable that signals...Ch. 4 - Prob. 14MCCh. 4 - Prob. 15MCCh. 4 - Prob. 16MCCh. 4 - The __________ section of a switch statement is...Ch. 4 - A ListBoxs index numbering starts at __________....Ch. 4 - You can use the __________ property to determine...Ch. 4 - The __________ property holds the item that is...Ch. 4 - Prob. 1TFCh. 4 - A single-alternative decision structure tests a...Ch. 4 - The if-else statement is a dual-alternative...Ch. 4 - A decision structure can be nested inside another...Ch. 4 - A compound Boolean expression created with the ...Ch. 4 - Prob. 6TFCh. 4 - Multiple CheckBox controls in the same GroupBox...Ch. 4 - The test expression in a switch statement can be a...Ch. 4 - If an item is not selected in a ListBox, the...Ch. 4 - Prob. 10TFCh. 4 - What is meant by the term conditionally executed?Ch. 4 - You need to test a condition and then execute one...Ch. 4 - Briefly describe how the operator works.Ch. 4 - Briefly describe how the || operator works.Ch. 4 - Prob. 5SACh. 4 - What is a flag and how does it work?Ch. 4 - What are the two arguments that you pass to a...Ch. 4 - How do you determine in code whether a RadioButton...Ch. 4 - Prob. 9SACh. 4 - Prob. 10SACh. 4 - Write an if statement that assigns 20 to the...Ch. 4 - Write an if statement that assigns 0 to the...Ch. 4 - Write an if-else statement that assigns 0 to the...Ch. 4 - Write nested decision structures that perform the...Ch. 4 - Write an if-else statement that displays Speed is...Ch. 4 - Write an if-else statement that determines whether...Ch. 4 - Prob. 7AWCh. 4 - Rewrite the following if-else-if statement as a...Ch. 4 - Prob. 9AWCh. 4 - Roman Numeral Converter Create an application that...Ch. 4 - Mass and Weight Scientists measure an objects mass...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Color Mixer The colors red, blue, and yellow are...Ch. 4 - Prob. 5PPCh. 4 - Book Club Points Serendipity Booksellers has a...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - Body Mass Index Program Enhancement In Programming...Ch. 4 - Change for a Dollar Game Create a change-counting...Ch. 4 - Fat Percentage Calculator One gram of fat has 9...Ch. 4 - Time Calculator Create an application that lets...Ch. 4 - Workshop Selector The following table shows a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
A recursive algorithm must _______ in the recursive case. a. solve the problem without recursion b. reduce the ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Why does locating a parting line on a sharp corner make that feature less noticeable?
Degarmo's Materials And Processes In Manufacturing
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th Edition)
A design technique that programmers use to break down an algorithm into functions is known as ________. a. top-...
Starting Out with Python (4th Edition)
24. If we increase the temperature in a reactor by 90 degrees Fahrenheit [°F], how many degrees Celsius [°C] wi...
Thinking Like an Engineer: An Active Learning Approach (4th 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
- True or False: The expression 6!0! equals 0.arrow_forwardThis is an operator used to assign a value to a variable. It works by transferring the value on its right to the variable on its left. greater than / equal (>=) equal (= =) less than / equal (<=) assignment (=)arrow_forwardConvert the following if-else-if statement into a switch statement if(choice==1) { System.out.println ("Its a 1."); } else if(choice==2 || choice==3) { System.out.println ("Its a 2 or 3"); } else if(choice==4) { System.out.println ("Its a 4"); else { System.out.println ("um, try again 1 4"); - }arrow_forward
- Using the following chart, write an if-else-if statement that assigns: S, M, L, depending on the weight: Weight Size Up to 120 lb S 120 lb to 175 lb M Over 175 lb Larrow_forwardConvert the following set of nested if-else statements to an if-else if statement: if (number == 1) { MessageBox.Show("One"); } else { if (number == 2) { MessageBox.Show("Two"); } else { if (number == 3) { MessageBox.Show("Three"); } else { MessageBox.Show("Unknown"); } } }arrow_forwardTrue or False? Every if statement must have a corresponding else.arrow_forward
- This needs to be made in Javascript. Leap Year Detector: Design a program that asks the user to enter a year, then displays a message indicating whether the year is a leap year. (If the year is evenly divisible by 100 and is also evenly divisible by 400, then it is a leap year. For example, 2000 is a leap year, but 2100 is not. If the year is not evenly divisible by 100 but is divisible by 4, then it is a leap year. For example, 1996 is a leap year, 1997 is not. )arrow_forwardThe data type bool: Group of answer choices Can only be used in a selection statement. Can take on any expression as a value. Can take on values -1, 0 or 1. Can take on values true and false.arrow_forward$1:Many processing controls are the same as output controls, particularly for online real time processing. $2:Control totals are generally processing controls A. Both Statements are trueB. Only the first statement is trueC. Only the second statement is trueD. None of the statements are truearrow_forward
- Web page bill calculator. User inputs the "item name" and "item amount" on the webpage. The webpage will return the total money he need to pay. If the payment is more than 30 dollars, the user can have a 10% off discount. Bill = (item cost )* (# of items) Item cost apple orange peach $1.2 $2arrow_forwardConvert the following if/elseif statement into a switch statement: if (choice == 1){cout << fixed << showpoint << setprecision(2); }else if ((choice == 2) || (choice == 3)) {cout << fixed << showpoint << setprecision(4); }else if (choice == 4) {cout << fixed << showpoint << setprecision(6); }else {cout << fixed << showpoint << setprecision(8); }arrow_forwardDIRECTIONS: Write the word TRUE if the statement is correct and if not, replace the underlined word(s) with the word(s) that will make the statement true. Example: Current that flows in a circuit can be limited using a transistor. Answer: transistor-resistor 1. Resistors can limit the flow of electric current. 2. Resistor is a passive device. 3. Capacitor can store electric charge. 4. Dielectric separates the two insulator sheets of a capacitor. 5. Passive device can be used as an amplifier.arrow_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
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