69.2k views
1 vote
A company issues $5,000.00 bonuses at the end of the year to all employees who earn less than $100,000. Salary and bonus are both defined as double data types. Which of the following selection statements would assign the correct amount to bonus?

a. if (salary bonus == $5000;b. if (salary bonus = 5000; --- Correctc. if (salary bonus = 5000;d. if (salary bonus = $5000;

1 Answer

2 votes

Answer: C.

If (salary < 100000)

Bonus = 5000;

Explanation:

Salaries attached to each employee are already in the data. Since only workers earns salary less than 100000 are eligible for the bonus, the if statement checks the salary amount assigned to each worker, if the salary is greater than or equal to 100,000 , the loop terminates and the second line isn't executed. However, if the worker's salary is less than 100,000, the second line is executed which is to assign a 5000 bonus to the worker's earning. The dollar sign should be excluded as it could alter the data type. And the == sign is used to test for equality and not assignment.

User Izaak Van Dongen
by
4.9k points