Write one or more \(\mathrm{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. Assign .10 to discount if dept equals 5 and price is less than \(\$ 100\). Assign .05 to discount if dept is anything else and price is less than \(\$ 100\).

Short Answer

Expert verified
Question: Write the C++ statements to determine the discount based on the value of 'dept' and 'price' using the solution provided. Answer: ```cpp if (dept == 5 && price >= 100) { discount = 0.20; } else if (dept == 5 && price < 100) { discount = 0.10; } else if (dept != 5 && price >= 100) { discount = 0.15; } else { discount = 0.05; } ```

Step by step solution

01

Check if dept equals 5 and price is greater than or equal to 100

To check if dept equals 5 and the price is greater than or equal to 100, we can use an if-else statement with the given condition: ```cpp if (dept == 5 && price >= 100) ```
02

Assign discount of .20

If the condition in step 1 is true, we can assign a discount of .20: ```cpp discount = 0.20; ```
03

Check if dept equals 5 and price is less than \(100\).

If the condition in step 1 is false, we proceed to check if dept equals 5 and price is less than 100, we can use an else if statement with the given condition: ```cpp else if (dept ==5 && price < 100) ```
04

Assign discount of .10

If the condition in step 3 is true, we can assign a discount of .10: ```cpp discount = 0.10; ```
05

Check if dept is anything else and price is greater than or equal to 100.

If the conditions in step 1 and step 3 are false, we proceed to check if dept is not equal to 5 and price is greater than or equal to 100, we can use an else if statement with the given condition: ```cpp else if (dept != 5 && price >= 100) ```
06

Assign discount of .15

If the condition in step 5 is true, we can assign a discount of .15: ```cpp discount = 0.15; ```
07

Assign discount of .05 in all other cases

If none of the conditions from step 1 to step 5 are true, we can assign a discount of .05 in the else block: ```cpp else discount = 0.05; ``` The final C++ statements combining all the steps: ```cpp if (dept == 5 && price >= 100) { discount = 0.20; } else if (dept == 5 && price < 100) { discount = 0.10; } else if (dept != 5 && price >= 100) { discount = 0.15; } else { discount = 0.05; } ```

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free