Concept explainers
Rewrite the following if/else statements as conditional expressions:
A) if (x > y)
z = 1;
else
z = 20;
B) if (temp > 45)
population = base * 10;
else
population = base * 2;
C) if (hours > 40)
wages *= 1.5;
else
wages *= 1;
D) if (result >= 0)
cout << "The result is positive\n";
else
cout << "The result is negative.\n”;
Learn your wayIncludes step-by-step video
Chapter 4 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Computer Science: An Overview (12th Edition)
Database Concepts (8th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
- c++ programming if…else and switch case are types of conditional selection statements used in many programming languages such as C++. Write your own codes for question (a), (b) and (c) to demonstrate how the selection statement works. (a) Using if….else selection statement, allow user to key in a number then check whether the number is positive or negative number. (b) Using if….else...if selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 .. (c) Using nested if..else selection statement, ask user to key in their age. Then define whether the user should go to nursery, primary school, secondary school or university based on their input. (d) Using switch case selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 .arrow_forwardUsing C++ program 1. ( Use if-else statement ) Write a program for asking for a quiz score. The program then will display a remark if FAILED or PASSED. The passing score is 50. Display also the lacking score points. 2. Why does the following section of code always print "ByeHi" no matter what x is? int x; cin>> x; if x(x < 0); cout<< "Bye"; cout<< "Hi\n"; 3. Write the general form of an if-else statement.arrow_forwardAn Auto Insurance Program Example - Write a program to determine the cost of an automobile insurance premium, based on driver's age and the number of accidents that the driver has had. The basic insurance charge is 500 Rs. There is a surcharge of 100 Rs if the driver is under 25 and there is an additional surcharge for accidents as can be seen below: No. of accidents Accident Surcharge 1 50 2 125 3 250 4 375 5 575 6 or more No insurance Note: Use switch cases when you check the total number of accidents.arrow_forward
- IN C LANGUAGE USING LADDERIZED IF-ELSE Create a program that will calculate Body Mass Index (BMI) and will indicate the status of your BMI. Using ladderized if-else. BMI = ([Weight in Pounds) / (Height in inches) x (Height in inches)] x 703 BMI = (Weight in Kilograms) / (Height in meters) x (Height in meters) Your program must accept weight in pounds or kilogram, and height in inches or meters. Formula: 1 ft = 12 inches 1 meter = 39.3701 iches 1 in = 0.0254 m 1 kg = 2.2 lb 1 lb = 0.454 kg BMI Categories: Underweight = <18.5 Normal weight = 18.5 - 24.9 Overweight = 25 - 29.9 Obesity = BMI of 30 or greater Sample Program: Weight (Input 1 for Lb, input 2 for kg): 1 Input weight in Lb: 220 Height (Input 1 for inches, input 2 for meters): 2 Input height in meters: 2 Your BMI is: 24.9 BMI Category: NORMAL WEIGHTarrow_forwardWrite multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has seat belts." If 1990 or later, print "Probably has antilock brakes." If 2000 or later, print "Probably has airbags." End each phrase with a period and a newline.arrow_forwardWrite an if-else statement that works like this: If the sales variable is greater- than or equal-to 50,000, the commissionRate variable should be assigned the value 0.2. Otherwise, the commissionRate variable should be assigned the value 0.1.arrow_forward
- Write a multiway if-else statement that classifies the value of an int variable ninto one of the following categories and writes out an appropriate message:n < 0 or 0 ≤ n < 100 or n ≥ 100Hint: Remember that the Boolean expressions are checked in order.arrow_forwardWrite if-else if statements that will compare "price" variable with below values and output statements based on the conditions price>=500 : “Extremely Expensive” price>=300 : “Very Expensive” price>=100: “Reasonable price “arrow_forwardConvert each if-else statement to a single assignment statement using a conditional expression, using parentheses around the condition. Enter "Not possible" if appropriate. 1) if x < 100: y = 0 else: y = xarrow_forward
- this is c program Write program that ask the user to enter int mark (0-100) for test Physics. Thencategorise the student based on the following grading system. Use else-if and switchstatements.Value output80-100 Gred A; Excellent60-79 Gred B; Very Good.40-59 Gred C;Good.0-39 Gred F;Failarrow_forwardUsing 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_forward1. Write an if statement that assigns 0 to x if y is equal to 20. 2. Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000. In Python Programming, please.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT