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
totalto0.0to store the total order price. - Iterate through the
itemsarray using a loop. The array size is equal ton, which is passed as the second parameter to thecalculateTotalOrderfunction. - For each item, check its name using
if / else ifand add the corresponding price tototal."Burger"β $5.0"Pizza"β $8.0"Hot dog"β $4.0
- Apply a 10% discount if the
totalexceeds $20 by multiplyingtotalby0.9. - Return the final
totalfrom 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
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 7.69
Challenge: Fast-Food Order Calculator
Swipe to show 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
totalto0.0to store the total order price. - Iterate through the
itemsarray using a loop. The array size is equal ton, which is passed as the second parameter to thecalculateTotalOrderfunction. - For each item, check its name using
if / else ifand add the corresponding price tototal."Burger"β $5.0"Pizza"β $8.0"Hot dog"β $4.0
- Apply a 10% discount if the
totalexceeds $20 by multiplyingtotalby0.9. - Return the final
totalfrom 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
Thanks for your feedback!
single