Concept explainers
The following if-else statement will compile and run without any problems. However, it is not laid out in a way that is consistent with the other if-else statements we have used in our
if (x < 0) {x = 7; cout << “x is now positive.”;}
else {x = –7; cout << “x is now negative.”;}
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
- Car experts recommend changing your air filter as often as every 6000 miles if the oil’s categoryis A. However, if the category is B, it is recommended to change the filter every 3000 miles. Write a programthat reads the oil’s category and the car trip miles then does the following:- Prints “Wrong category” if the category entered by the user is different than ‘A’ and ‘B’.- Prints “You should change your car filter!” if it is time to change the filter according to the category (i.e.when miles are above 6000 for A or miles are above 3000 for B).- If it is not the time to change the filter, the program prints the remaining miles and wishes the driver asafe drive. (use while)arrow_forwardCar experts recommend changing your air filter as often as every 6000 miles if the oil’s categoryis A. However, if the category is B, it is recommended to change the filter every 3000 miles. Write a programthat reads the oil’s category and the car trip miles then does the following:- Prints “Wrong category” if the category entered by the user is different than ‘A’ and ‘B’.- Prints “You should change your car filter!” if it is time to change the filter according to the category (i.e.when miles are above 6000 for A or miles are above 3000 for B).- If it is not the time to change the filter, the program prints the remaining miles and wishes the driver asafe drive.arrow_forwardCan you please help me write an if/else statement for the following picture The language is Javaarrow_forward
- This is 2nd time i post the same question if you don't know the answer left it otherwise I down-voted you. Question : if there are 100 question and each question have 4 options Write a program in any one language (java, c, c++,python) to find all combination of answer.arrow_forwardIn which cases you can transform an else-if statements to switch? Provide an example.arrow_forwardThe following code is supposed to output the string in lowercase letters but ithas an error. What is wrong?String test = "WHY ARE YOU SHOUTING?";test.toLowerCase();System.out.println(test);arrow_forward
- Re- write the following program by using switch statement int main() { int code; Cout<<"enter code(a or A, bo B"; Cin>>Code; If ( code == 'a' && code =='A'} cout < < ''Sometimes you win" cout<< " Sometimes you learn"; else if (code =='b' &&& code== 'B') cout < < ''Don't wait for the perfect moment"; cout<< " Take the moment and make it perfect"; else Cout<<"Wrong code entered"; Return 0;arrow_forwardIn this lab, you use the flowchart and pseudocode found in the figure below to add code to a partially created Java program. When completed, college admissions officers should be able to use the Java program to determine whether to accept or reject a student, based on his or her test score and class rank. start input testScore, classRank if testScore >= 90 then if classRank >= 25 then output "Accept" else output "Reject" end if else if testScore >= 80 then if classRank >= 50 then output "Accept" else output "Reject " endif else if testScore >= 70 then if classRank >= 75 then output "Accept" else output "Reject" end if else out put "Reject" end if end if end if stop Instructions Study the pseudocode in picture above. Declare the variables testScoreString and classRankString. Write the interactive input statements to retrieve: A student’s test score (testScoreString) A student's class rank (classRankString) Write the statements to convert the string representation…arrow_forwardMulti-way selection is possible with nested if-else statements and switch statements. When is it inappropriate to use a switch statement?arrow_forward
- What does the 'and' Boolean operator do? a. It compares two conditions. Only if both are True is the result True b. It compares two conditions. If at least one is True, the result is True. c. It flips the value of a condition from True to False or False to True d. It compares two conditions. If one but not both of the conditions is True, the result is True A condition in an if-statement can evaluate to what possible conditions? a. 0, 1 and 2 b. any number of values c. either True or False d. good, fair, serious or fatal What does int(g) mean? a. int is a mathematical function that performs integration on the number contained in g. b. int converts the value in g from a string to a whole number. c. int computes the compounded interest rate of g. d. int makes the value of g intermittentarrow_forwardFind out the final values of a,b and c where following expressions are executed sequentially:[4]int a = 2, b =3, c;a = (b++) + (++b) + a;c = a>b ? a:b;b = (a++) + (b--) + a;c = c++*b--;arrow_forwardThe else in a set of if statements is sometimes called the "catch all"? Is this true or false?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