Challenge: Calculate Shipping Cost
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.
- Inside the function
calculateShipping
, set the initialshippingPrice
to 10% ofproductPrice
. - If the product's weight exceeds 25 pounds, add an additional $2.25 to
shippingPrice
. - Use a
switch
statement on theoption
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.
- Case 1 → add $0.3 to
- 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
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: Calculate Shipping Cost
Deslize para mostrar o menu
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.
- Inside the function
calculateShipping
, set the initialshippingPrice
to 10% ofproductPrice
. - If the product's weight exceeds 25 pounds, add an additional $2.25 to
shippingPrice
. - Use a
switch
statement on theoption
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.
- Case 1 → add $0.3 to
- 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
Solução
solution.cpp
Obrigado pelo seu feedback!
single