Challenge: Fast-Food Order Calculator
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.
- Initialize a variable
total
to0.0
to store the total order price. - Iterate through the
items
array using a loop. - For each item, check its name using
if / else if
and add the corresponding price tototal
."Burger"
→ $5.0"Pizza"
→ $8.0"Hot dog"
→ $4.0
- Apply a 10% discount if the
total
exceeds $20 by multiplyingtotal
by0.9
. - 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
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 7.69
Challenge: Fast-Food Order Calculator
Deslize para mostrar o menu
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.
- Initialize a variable
total
to0.0
to store the total order price. - Iterate through the
items
array using a loop. - For each item, check its name using
if / else if
and add the corresponding price tototal
."Burger"
→ $5.0"Pizza"
→ $8.0"Hot dog"
→ $4.0
- Apply a 10% discount if the
total
exceeds $20 by multiplyingtotal
by0.9
. - 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
Obrigado pelo seu feedback!
single