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

bookChallenge: Fast-Food Order Calculator

Tarefa

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.
  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)

Solução

solution.cpp

solution.cpp

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

close

Awesome!

Completion rate improved to 7.69

bookChallenge: Fast-Food Order Calculator

Deslize para mostrar o menu

Tarefa

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.
  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)

Solução

solution.cpp

solution.cpp

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2
single

single

some-alt