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

bookChallenge: Fast-Food Order Calculator

Compito

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)

Soluzione

solution.cpp

solution.cpp

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

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

Scorri per mostrare il menu

Compito

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)

Soluzione

solution.cpp

solution.cpp

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 2
single

single

some-alt