Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Fast-Food Order Calculator | Conditional Control Flow Practice
C++ Conditional Statements

bookChallenge: Fast-Food Order Calculator

Task

Swipe to start coding

You are building a fast-food ordering system. Customers can select multiple items from the menu, and you want to calculate the total price of their order. Additionally, if the total exceeds a certain amount, a discount is applied.

  1. Initialize a variable total to 0.0 to store the total order price.
  2. Iterate through the items array using a loop. The array size is equal to n, which is passed as the second parameter to the calculateTotalOrder function.
  3. For each item, check its name using if / else if and add the corresponding price to total.
    • "Burger" β†’ $5.0
    • "Pizza" β†’ $8.0
    • "Hot dog" β†’ $4.0
  4. Apply a 10% discount if the total exceeds $20 by multiplying total by 0.9.
  5. Return the final total from the function.

Example

{"Burger", "Pizza", "Hot dog"} β†’ $17.0 (no discount)
{"Pizza", "Pizza", "Burger"} β†’ $18.9 (after 10% discount)
{"Pizza", "Pizza", "Burger", "Hot dog"} β†’ $21.6 (after 10% discount)

Solution

solution.cpp

solution.cpp

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

Awesome!

Completion rate improved to 7.69

bookChallenge: Fast-Food Order Calculator

Swipe to show menu

Task

Swipe to start coding

You are building a fast-food ordering system. Customers can select multiple items from the menu, and you want to calculate the total price of their order. Additionally, if the total exceeds a certain amount, a discount is applied.

  1. Initialize a variable total to 0.0 to store the total order price.
  2. Iterate through the items array using a loop. The array size is equal to n, which is passed as the second parameter to the calculateTotalOrder function.
  3. For each item, check its name using if / else if and add the corresponding price to total.
    • "Burger" β†’ $5.0
    • "Pizza" β†’ $8.0
    • "Hot dog" β†’ $4.0
  4. Apply a 10% discount if the total exceeds $20 by multiplying total by 0.9.
  5. Return the final total from the function.

Example

{"Burger", "Pizza", "Hot dog"} β†’ $17.0 (no discount)
{"Pizza", "Pizza", "Burger"} β†’ $18.9 (after 10% discount)
{"Pizza", "Pizza", "Burger", "Hot dog"} β†’ $21.6 (after 10% discount)

Solution

solution.cpp

solution.cpp

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

some-alt