# assignment 570

1. Write a C statement that prints the message â€œThe number is valid.â€ If the variable grade is within the range 0 through 100.

2. Write a C statement that prints the message â€œThe number is not valid.â€ If the variable hours is within the range 0 through 80.

3. Describe the output produced by the following program segment. (Assume x and y are integers.)

if (x >= y)
printf(x);
else

printf(y);

(a)when x = 2 and y = 5

(b)when x = 4 and y = 4

(c)when x = 3 and y = 8

(d)when x = 5 and y = 5

(e)when x = -1 and y = -1

4. Using the following chart, write a C statement that assigns .10, .15, or .20 to commission, depending on the value in sales.

 Sales Commission Rate Up to \$10,000 10% \$10,000 to \$15,000 15% Over \$15,000 20%

5. Write one or more C statements that assign the correct value to discount, using the logic described here:
Assign .20 to discount if dept equals 5 and price is \$100 or more.
Assign .15 to discount if dept is anything else and price is \$100 or more.

6. The following statement should determine if x is not greater than 20. What is wrong with it?
if (!x > 20)

7. The following statement should determine if count is within the range of 0 through 100. What is wrong with it?
if (count >= 0 || count <= 100)

8. Describe the output produced by the following program segment. (Assume number is an integer.)

switch (number)

{

case 100:

printf(“%dn”, number+99);

break;

case 50:

printf(“%dn”, number-1);

default:
printf(â€œdefaultnâ€);

}

(a)when number is 100

(b)when number is 50

(c)when number is -1

Now omit the break statement in problem #1 and describe the output for each.

(a)when number is 100

(b)when number is 50