Explain why the following code sample does not capture the intent of the request "Make sure if the sales code is not 'A' or 'B', the customer gets a 10% discount". What is the correct if statement?if(salesCode != 'A' || salesCode != 'B')discount = 0.10;

What will be an ideal response?


Whenever you use negatives, it is easy to make logical mistakes. The following statement will result in every customer receiving the 10% discount because every salesCode is either not 'A' or not 'B'. For example, a salesCode of 'A' is not 'B'.
if(salesCode != 'A' || salesCode != 'B')
discount = 0.10;
The statement above is always true. The correct statement is one of the following:
if(salesCode != 'A' && salesCode != 'B')
discount = 0.10;
if(!(salesCode == 'A' || salesCode == 'B'))
discount = 0.10;

Computer Science & Information Technology

You might also like to view...

____________________ can only be applied when the object is placed using absolute positioning.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code. Scanner input = new Scanner(System.in); double v1 = input.nextDouble(); double v2 = input.nextDouble(); String line = input.nextLine();

a. After the last statement is executed, line contains characters '7', '8', '9'. b. After the last statement is executed, line contains characters '7', '8', '9', '\n'. c. After the last statement is executed, line contains characters ' ', '7', '8', '9', '\n'. d. After the last statement is executed, line contains characters ' ', '7', '8', '9'.

Computer Science & Information Technology

A standard hardware environment that imitates the function of a computer system is provided within each ______________ machine for each guest OS.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A(n) ________ function returns one value if the first argument is true and another value if it is false

Fill in the blank(s) with correct word

Computer Science & Information Technology