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

book
Calculate Shipping Cost

Tarea

Swipe to start coding

  1. Create a shipping cost calculator. The initial shipping cost is set at 10% of the product's price.
  2. If the product's weight exceeds 25 pounds, an additional $2.25 is added to the shipping cost.
  3. For products weighing over 25 pounds, you have to choose between three delivery options from the slowest to the fastest. Each of these options add an extra cost of $0.3, $0.5, and $1.75, respectively.
  4. Calculate and display the final shipping cost for the product.

Solución

cpp

solution

#include <iostream>

int main()
{
float weight = 27.6;
int option = 2;

float price_of_product = 21.99;
float shipping_price = price_of_product * 0.1;
if (weight > 25)
{
shipping_price += 2.25;
switch (option)
{
case 1:
shipping_price += 0.3;
break;
case 2:
shipping_price += 0.5;
break;
case 3:
shipping_price += 1.75;
break;
}
std::cout << shipping_price << std::endl;
}
}

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4
#include <iostream>

int main()
{
float weight = 27.6;
int option = 2;

float price_of_product = 21.99;
float shipping_price = ___;
if (___)
{
shipping_price += 2.25;
switch (___)
{
case _:
shipping_price += ___;
break;
case 2:
shipping_price += ___;
___;
case _:
shipping_price += 1.75;
___;
}
std::cout << shipping_price << std::endl;
}
}

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

We use cookies to make your experience better!
some-alt