Explain how the if statement checks the input. Your code is if(!(commodity_code=='A'|| commodity_code=3'B'||commodity_code=='C'))
Q: Write an if/else statement that assigns .10 to the variable discount if the Boolean flag variable…
A: Solution: Given : if boolean flag variable prepaid is false discount ==0.10 and if true the…
Q: Explain how the if statement checks the input. Your code is if(!(commodity_code=='A'||…
A: If statement: If statement is used in programming in language to check a specific condition for a…
Q: if (a > 0) b3а +10; else b%3а -10;
A: Below is the equivalent MIPS assembly language for the given c fragments. MIPS stands for…
Q: Write an if statement that multiplies payRate by 1.5 if hours is greater than 40.
A: Answer: An if statement that multiplies payRate by 1.5 if hours is greater than 40.
Q: What are differences between switch statement and if-else if statement control
A: Note: There are multiple questions are given in one question. According to the rule, you will get…
Q: Write an if statement for the following: use if/else statement that assigns 0.10 to commission…
A: #include<stdio.h> int main() { float sales, commission; printf("Enter sales : "); scanf("%f",…
Q: Rewrite the following code segment using if-else statement instead of switch statement: switch (i)…
A: If-else statements are used in case of conditional programming.
Q: True or False? Every if statement must have a corresponding else.
A: Given, Statement: Every if statement must have a corresponding else.
Q: A cashier distributes change using the maximum number of five dollar bills, followed by one dollar…
A: Code comments have been added in the code for better explanation of the code for your reference.
Q: Write an if statement that assigns 30 to y when x lies between 1 and 10.
A: Given : Write an if statement that assigns 30 to y when x lies between 1 and 10.
Q: Write an if statement that increases pay by 3% if score is greater than 90, otherwise increases pay…
A: if(condition){ statement; ...}else{ statements; ...}
Q: The else statement doesn't have a conditional expression. True False You can only have one case…
A: All the above questions are related to control flow statements. Control flow statements are used to…
Q: Rewrite the following statement with an if/else statement: total += count = = 1? sales : count *…
A: if((total+count)==1) { Print sales; } else { Print count * sales; }
Q: Write the shortest condition in the if-statement below that will mak unshaded values of row two (2)…
A: Given : Consider row 2 :
Q: Write an if-else statement that works like this: If the sales variable is greater- than or equal-to…
A: “if-else” statement: The following is the “if” statement to assign 0.2 to the variable…
Q: Determine whether the following is valid switch statement. If not, explain why. Assume that n is an…
A: C++ Switch Statements Use the switch statement to select one of the many code blocks to be executed.…
Q: Rewrite the following nested if-else statement as a single if-else, with a compound condition: 1) {…
A: Your C++ program is given below with complete implementation and output.
Q: By using the aid of flowchart(s), explain the difference between if selection and if. else…
A: if statement: The if statement is the fundamental control statement that allows JavaScript to make…
Q: Write an if/else statement that assigns 0.10 to commission unless sales is greater than or equal to…
A: #include<stdio.h> int main() { float sales, commission; printf("Enter sales : "); scanf("%f",…
Q: Q/The equivalent statements for the following code are for(i=4;i>=0; i--) switch (i) {case 0:…
A: The correct answer is There is no right choice. The given code has few missing elements which does…
Q: What is the if statement line that checks is String s1 is case insensitively greater than String s2.
A: compareToIgnoreCase() - This method is used to compare two strings lexicographically, ignoring lower…
Q: You can always convert a multi-way if-else statement to an equivalent switch statement. True False
A: We can only use: integers or characters in case statement of switch statement. So we can not use…
Q: If the sub-expression on the left of the || logical operator is __________, the right sub-expression…
A: If the sub-expression on the left of the & & logical operator is false, the right…
Q: Write an if statement that increases pay by 3% if score is greater than 90, otherwise it increases…
A: If statement according to the need of yours is given below:
Q: c. Write aprogram using nested if statements that perform the following test: If the variable…
A: Write a program using nested if that will the following conditions and then display the result.…
Q: Convert the following if-else-if statement into a switch statement
A: Step 1:- Given:- if(choice==1) { System.out.println("Its a 1."); } else if(choice==2 II choice==3)…
Q: Multi-way selection is possible with nested if-else statements and switch statements. When is it…
A: Its possible to use Switch case and nested if else in case of myltiway selection.
Q: Write an if/else statement that assigns 0 to x when y is equal to 10. Otherwise it should assign 1…
A: if(y==10) { x=0; } else { x=1; }
Q: Write the shortest condition in the if-statement below that will make the unshaded values of row…
A: for ques number 8 num >16 and num <20 and num != 19 for row 9 num ==8 or num >=16 and…
Q: Rewrite the following expressions as C++ assignment statements that use the conditional operator.…
A: The syntax of the conditional operator is as follows: Expression1 ? Expression2 : Expression3 If…
Q: Write an if statement for the following : use if statement that sets the variable fees to 50 if…
A: int fees; bool flag,max; flag=max; if(max==true) { fees=50; } printf("\n%d",fees);
Q: Rewrite the following switch statement using a nested if-else structure (assume that n is a…
A: Above mentioned switch -case statement is converted to nested if-else statements. Equivalent Nested…
Q: Write an if statement that assigns 0.2 to commissionRate if sales is greater than or equal to 10000.
A: Answer:- if(sales>=10000.00) commissionRate = 0.20;else commissionRate = 0.10; I have…
Q: Use the Block IF statement to do the following where n has been declared as an integer and x as a…
A: Required:
Q: Using the following chart, write if/elif statements that assigns .10, .15, or .20 to commission,…
A: A pictorial representation of steps used to solve a problem is called flowchart. Each symbol used in…
Q: Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5 <x < 2.5, and 3…
A: The above question is solved in step 2 and step 3 :-
Q: What is the difference between if and switch statement?
A: Conditional Statements are utilized to settle on choices dependent on the conditions. They execute…
Q: if (a > 0) if (b 5) x - x + 4; else x - x + 3; else x -x + 2; « is currently 0, a is 1 and b is -1,…
A: Here in this question we have given a Java code and we have asked to find the final value of x after…
Q: Convert the following if/else if statement into a switch statement: if (choice == 1) { sout « "1…
A: Solution: Given,
Q: Write an if statement that determines whether the variable sales is greater than or equal to 10,000.…
A: Required “if” statement: The following is “if” statement assigns a value “0.2” to the variable…
Q: When you code an if statement within another if statement, as in the following, then the if…
A: The correct answer is Nested If Statement. When you code an if statement within another if…
Q: When you write an if-else statement, under what circumstances do the statements that appear after…
A: The if-else statement is used at the point in a program where decision-making is required based on…
Q: QUESTION 8 Write an if/else statement that compares the value of two variables, lastYrTaxes and…
A: The question is on: writing the code in java with respect to the given question.
Q: Write an if statement that performs the following logic: if the value of variable price is greater…
A: If statement If the statement is intended to change the course of action.The syntax of the statement…
Q: A one-way if statement performs an action if the specified condition is true. If the condition is…
A: An if statement is followed by its else part which will be executed only if the "IF" condition is…
Q: Write an if statement that increases pay by 3% if score is greater than 90, other- wise increases…
A: Write an if statement that increases pay by 3% if score is greater than 90, other- wise increases…
Q: Write the shortest condition in the if-statement below that will make the unshaded values of row…
A: Given list of binary operators for conditions, < is less than operator i.e. a<b returns true…
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Step by step
Solved in 2 steps
- Kindly fix the errors in this assignmentI'm getting an error on error: expected ' ' before ' '} else if (grade == 'B') { (I cannot see the error)[ Here is the assignement ] Write an structure that will print a message based on the grade ( A,B,C,D,or F). Do this first using an if statement. Then do it using a switch statement. The grade and message are as follows. • A Excellent Job • B Very Good • C Average • D Need more effort ------- code -------#include <stdio.h> int main() { char grade; printf("please enter your grade (A, B,C,D, or F): "); scanf("%c", &grade); // Using if statement if (grade == 'A'){ printf("Excellent job!\n");{ } else if (grade == 'B') { printf("Very good!\n"); } else if (grade == 'C') { printf("Average. n"); } else if (grade == 'D') { printf("You need more effort.\n"); } else if (grade == 'F') { printf("You need to get some help. \n"); } else { printf("Invalid grade entered.\n"); } //…Question Using Java programming language write a program to manage a hotel with 24 rooms;10 rooms are Executive, with price Gh ₵ 2500.00 per night,7 rooms are Chalets, with amounts Gh ₵ 1500.00 per night7 rooms are Ordinary, with amount Gh ₵ 500.00 per night The program should allow customers to book for rooms for a number of nights, and update the number of empty rooms available for each category when a customer has paid fully and has checked-in; also update the number of empty rooms available when customer checks-out.Customers should make bookings with their first names, telephone number A customer should be prompted to know if a room is booked (meaning a another customer has booked it but has not paid fully, or has not checked-in) A customer should be prompted to know if a room is occupied (meaning a booked room has been fully paid for, or the customer has checked-in) A customer should be prompted to know if a room is available (meaning a room has neither been booked nor…Problem Statement: A 4th grader is having trouble with Permutation and Combination problem in Mathematics, so a friend offered help to create a program they can use. The program contains 3 options, 1st option is for Permutation, 2nd option is Combination and 3rd is for terminating the system. For option 1, Permutation, they uses the following formula: nPr = ; where r must not be greater than n. It should not proceed if this condition is not met. For 2nd option, Combination, they uses the formula : nCr = ; where r must not be greater than n as well. For the 3rd option, the program owner’s information shall be displayed, like name, subject code and account number, before the program terminates. Requirements: Develop the required system and use cpp for the file name Remember that both n and r are variables, their values shall only be entered at run time. The program requires the use of any looping The program requires the use of any conditional Introduce at least 2…
- e11: Find the value of A for the following: A = (5 + 2* 3+ (( 3-2)* 7)+ -9) /2.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;Interest on a credit card’s unpaid balance is calculated using the average daily balance. Suppose that netBalance is the balance shown in the bill, payment is the payment made, d1 is the number of days in the billing cycle, and d2 is the number of days payment is made before billing cycle. Then, the average daily balance is: averageDailyBalance = (netBalance * d1 – payment * d2) / d1 If the interest rate per month is, say, 0.0152, then the interest on the unpaid balance is: interest = averageDailyBalance * 0.0152 Write a program that accepts as input netBalance, d1, payment, d2, and interest rate per month (interestRate). The program outputs the interest. Format your output to two decimal places.
- -scripting language Write a program that randomly generates a lottery between 100 and 999 (random.randint(100, 999)), prompts the user to enter a number in the same range, and determines whether the user wins according to the following rule: (1) If the user input matches the lottery in exact order, print "the award is $10,000". E.g., lottery = 123, input = 123(2) If the user input matches the lottery, but in wrong order, print "the award is $6,000". E.g., lottery = 123, input = 321(3) If two digits in the user input matches a digit in the lottery, print "the award is $3,000". E.g., lottery = 123, input = 612(4) If one digit in the user input matches a digit in the lottery, print "the award is $1,000". E.g., lottery = 123, input = 289(5) If none of the digits is matched, print "thank you".Interest on a credit card’s unpaid balance is calculated using the average daily balance. Suppose that netBalance is the balance shown in the bill, payment is the payment made, d1 is the number of days in the billing cycle, and d2 is the number of days payment is made before billing cycle. Then, the average daily balance is: averageDailyBalance = (netBalance * d1 – payment * d2) / d1 If the interest rate per month is, say, 0.0152, then the interest on the unpaid balance is: interest = averageDailyBalance * 0.0152 Instructions Write a program that accepts as input netBalance, d1, payment, d2, and interest rate per month (interestRate). The program outputs the interest. Format your output to two decimal places. Input: 100 30 50 7 9.7 Output: 856.83 Test case 2: Input: 255.76 31 55 3 12.3 output: 3080.38Lab: 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…