Concept explainers
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?");
}
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out With Visual C# (5th Edition)
Additional Engineering Textbook Solutions
Degarmo's Materials And Processes In Manufacturing
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Concepts Of Programming Languages
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Introduction To Programming Using Visual Basic (11th Edition)
- Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows: If a customer purchases no books, he or she earns 0 points If a customer purchases 1 through 5 books, he or she earns 5 points for each book. If a customer purchases 6 through 10 books, he or she earns 10 points for each book. If a customer purchases 11 or more books, he or she earns points equal to 20 points for each book. (Use Python) Use the Design Recipe to write the function customer_rewards which consumes the number of books purchased, and returns the total points. Include a docstring! Write 3 assert_equal statements to test your function.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_forwardTrue or False? Every if statement must have a corresponding else.arrow_forward
- Lab: switch Note: switch syntax is only applied for service selection. You can use if – else syntax for other comparison. Using switch syntax to write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minutes. Premium service: $25 plus For calls made from 6:00 a.m to 6:00 p.m., the first 75 minutes are free; charges for more than 75 minutes are $0.10 per minute. For, calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for more than 100 minutes are $0.05 per minute. Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code for r or R means regular service; a service…arrow_forwardTrue or False: The expression 6!0! equals 0.arrow_forwardExercise: Complete the switch statement, and add the correct keyword at the end to specify some code to run if there is no case match in the switch statement. int day = 4; switch (day) { case 1: cout << "Saturday"; break; case 2: cout << "Sunday"; break; default): cout << "Weekend"; } Show Answerarrow_forward
- 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 endarrow_forward! 1000$ by default, but discounts are applied to it based on different criteria. 1- Students get 20% discount. 2- People who purchase in 30 days in advance get 25% discount. 3- student purchasing 40 days in advance gets a 40% discount. This code segment calculates the final price. x = Text1.Text If x= "student" Then 1-... ElseIf x= "advance" Then price 1000 - 0.25 * 1000 ElseIf x= "stu_adv" Then price 1000 - 0.4 * 1000 2-...... price = 1000 3-..... 4-.. O = 1-price = 1000 - 0.2 * 1000 2-Else 3- End If 4-Print price 1-price 1000 - 0.2 * 1000 2-Else 3- Print price 4-End If 1-price = 3-End If 4-Print price = 1000 -0.2 * 1000 2-Elseifarrow_forward> Example: Rewrite the previous code by using nested if condition. grade (x) := if x2 60 grade (50) = "you fail" out e "you get a D" if x2 70 grade (61) = "you get a D" out + "you get a C" if x2 80 grade (75) = "you get a C" out + "you get a B" grade (88) = "you get a B" out "you get an A" if x2 90 out + "you fail" otherwise grade (93) = "you get an A" outarrow_forward
- Language is VB Write a selection statement (if .....then .... else .... end-if) that evaluates a voter age to allow her/him to vote. If age is equal or greater than 18 then display the message 'you can vote.' ,otherwise display "you are too young to vote" on a label control or object . You pick the name for the integer variable whose content is the number indicating the age and pick a name for the label whose content indicating the appropriate message. if ........ then ............. else .......... end-ifarrow_forwardConvert the following if statements into a switch statement:if (time == 0){greeting = "Good morning";}else if (time == 1){greeting = "Good day";}else if (time = 2){greeting = "Good evening";}else if (time == 3){greeting = "Good night";}arrow_forwardWrite an if statement with a condition using the random function from the random module that you would expect to be true about 30% of the time. The answer starts with if random.random(.arrow_forward
- 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