Explanation of Solution
Given statements:
//Switch to score
switch (score)
{
//Case
case (score > 90):
//Assign the grade
grade = 'A';
//Break the statement
break;
//Case
case (score > 80):
//Assign the grade
grade = 'b';
//Break the statement
break;
//Case
case (score > 70):
//Assign the grade
grade = 'C';
//Break the statement
break;
//Case
case (score > 60):
//Assign the grade
grade = 'D';
//Break the statement
break;
//Default Case
default:
//Assign the grade
grade = 'F';
}
Error in the given statement:
Error #1:
The case statements itself cannot contain an expression. The “case” must be carried out with an integer or a character. The given code cannot be modified as the “switch” statement because it contains expressions. It can only be converted into “if-else-if” statement that is given below...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- 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_forwardCircle Properties Write a program that prompts for and accepts the diameter of a circle as a floating point number. The program should calculate and output the area and circumference of the circle. A sample run of the program should look like this: Enter circle diameter: 2.5 The area is 4.91 and the circumference is 7.85. Use 3.14159 as your constant for pi. global main ; exposes program entry point to the linkerextern printf ; declare external functionextern scanf section .text ; start of code segment main: push rbp ; preserve base pointer mov rbp,rsp ; copy stack pointer to base pointer pop rbp ; restore base pointer mov rax, 0 ; exit status (0 = success) ret section .data ; start of initialized data segment section .bss ; start of uninitialized data segment section .dataprompt db "Enter circle diameter: ", 0format db "The area is %0.2f and the circumference is %0.2f.", 0pi dq 3.14159…arrow_forwardProblem definition: A college wants to know how well its students did on an exam. The following program summarizes the results. The program asks a user to enter the results pass (1) or fail (2) for 10 students. It displays the number of passed and the number of failed. It displays a message "Raise error" if the number of passes is more than 8 You are asked to identify statement with syntax errors by selecting them as wrong and the correct statements as rightarrow_forward
- flowchart, create.arrow_forwarddef integer_0_or_1(interger): #if value is true return 1 if truth_value: return 1 else: #else return 0 return 0def truth_value(integer): """Convert an integer into a truth value.""" # Convert 0 into False and all other integers, # including 1, into True if integer == 0: truth_value = False else: truth_value = True return truth_value print(truth_value(True))print(truth_value(False)) This question assesses Block 2 Part 4. It assumes an understanding of binary notation and truth tables (Block 1 Part 1). Write a function and_binary(), which takes two integers (each is either 0 or 1) and returns an integer in accordance with the truth table: A B and_binary(A, B) 0 0 0 0 1 0 1 0 0 1 1 1 Before you dive into writing your function, first decompose the problem. Then, write an algorithm. Only after that, implement your solution in Python. Hint: When you have decomposed the…arrow_forwardValidy options is: Valid / Invalidarrow_forward
- The code segment will display PTUKPTUK: int value = 1; value++; switch (value) { case 1: cout << "PTUK"; case 1 + 1: cout << "PTUK" << "PTUK";break; default: cout << "PTUK"; } Select one: O True Falsearrow_forwardMadLib Game bigGame.py Write a program that plays a MadLib game with the user. The program should ask the user to enter the following words: A plural noun (PNOUN1) A person’s first name (FNAME) A noun (NOUN1) A person’s last name (LNAME) A second plural noun (PNOUN2) A place (PLACE1) A third plural noun (PNOUN3) Another place (PLACE2) A fourth plural noun (PNOUN4) A second noun (NOUN2) An adjective (ADJECTIVE1) A second adjective (ADJECTIVE2) A verb (VERB) A third adjective (ADJECTIVE3) After the user has entered these items, the program should display the following story, inserting the user’s input into the appropriate locations: Hello there, sports PNOUN1!This is FNAME, talking to you from the press NOUN1in LNAME Stadium, where 57,000 cheering PNOUN2Have gathered to watch (the) PLACE1 PNOUN3take on (the) PLACE2 PNOUN4.Even though the NOUN2 is shining, it’s a/an ADJECTIVE1cold day with the temperature in the ADJECTIVE2 20s.We’ll be back for the opening VERB -off after a few…arrow_forwarddef print_num_pattern(num1, num2): if num1 <=0: print("0", end="") return print(num1, end="") print_num_pattern(num1 - num2, num2) print(num1, end="") if __name__ == "__main__": num1 = int(input()) num2 = int(input()) print_num_pattern(num1, num2)arrow_forward
- Write a statement that assigns finalValue with the multiplication of userNum1 and userNum2. Ex: If userNum1 is 6 and userNum2 is 2, finalValue is 12. let userNum1 = 6; // Code tested with values: 6 and 4let userNum2 = 2; // Code tested with values: 2 and -2 let finalValue = 0;arrow_forwardLab: 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_forwardUse C Language Airline Reservation System A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "economy" If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT