Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Calculate Shipping Cost | Conditional Control Flow Practice
C++ Conditional Statements

bookChallenge: Calculate Shipping Cost

Tehtävä

Swipe to start coding

You are building a shipping cost calculator that computes the final shipping price for a product based on its weight and selected delivery option.

  1. Inside the function calculateShipping, set the initial shippingPrice to 10% of productPrice.
  2. If the product's weight exceeds 25 pounds, add an additional $2.25 to shippingPrice.
  3. Use a switch statement on the option parameter:
    • Case 1 → add $0.3 to shippingPrice.
    • Case 2 → add $0.5 to shippingPrice.
    • Case 3 → add $1.75 to shippingPrice.
    • Default → do nothing.
  4. Return the value of shippingPrice from the function.

Example

calculateShipping(27.6f, 21.99f, 2)4.95 calculateShipping(24.0f, 50.0f, 1)5.00 calculateShipping(30.0f, 100.0f, 3)13.35

Ratkaisu

solution.cpp

solution.cpp

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 4
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

Awesome!

Completion rate improved to 7.69

bookChallenge: Calculate Shipping Cost

Pyyhkäise näyttääksesi valikon

Tehtävä

Swipe to start coding

You are building a shipping cost calculator that computes the final shipping price for a product based on its weight and selected delivery option.

  1. Inside the function calculateShipping, set the initial shippingPrice to 10% of productPrice.
  2. If the product's weight exceeds 25 pounds, add an additional $2.25 to shippingPrice.
  3. Use a switch statement on the option parameter:
    • Case 1 → add $0.3 to shippingPrice.
    • Case 2 → add $0.5 to shippingPrice.
    • Case 3 → add $1.75 to shippingPrice.
    • Default → do nothing.
  4. Return the value of shippingPrice from the function.

Example

calculateShipping(27.6f, 21.99f, 2)4.95 calculateShipping(24.0f, 50.0f, 1)5.00 calculateShipping(30.0f, 100.0f, 3)13.35

Ratkaisu

solution.cpp

solution.cpp

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 4
single

single

some-alt