Challenge: Math Operation Handler
Swipe to start coding
You're building a simple math operation processor that performs different calculations based on the selected operation type.
Use a switch
statement to handle each operation type.
- Addition (
case 1
)- Add
a
andb
. - Print
"Adding numbers..."
.
- Add
- Subtraction (
case 2
)- Subtract
b
froma
. - Print
"Subtracting numbers..."
.
- Subtract
- Multiplication (
case 3
)- Multiply
a
byb
. - Print
"Multiplying numbers..."
.
- Multiply
- Division (
case 4
)- Check if
b
is not equal to zero. - If true, divide
a
byb
and print"Dividing numbers..."
. - Otherwise, print
"Error: Division by zero not allowed."
.
- Check if
- Default Case
- Print
"Invalid operation type."
if the number doesn't match any valid case.
- Print
- Return the result of the performed operation.
Example
operationType = 3
, a = 12.0
, b = 4.0
=> "Multiplying numbers..."
and return 48.0
.
Solución
solution.cpp
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 7.69
Challenge: Math Operation Handler
Desliza para mostrar el menú
Swipe to start coding
You're building a simple math operation processor that performs different calculations based on the selected operation type.
Use a switch
statement to handle each operation type.
- Addition (
case 1
)- Add
a
andb
. - Print
"Adding numbers..."
.
- Add
- Subtraction (
case 2
)- Subtract
b
froma
. - Print
"Subtracting numbers..."
.
- Subtract
- Multiplication (
case 3
)- Multiply
a
byb
. - Print
"Multiplying numbers..."
.
- Multiply
- Division (
case 4
)- Check if
b
is not equal to zero. - If true, divide
a
byb
and print"Dividing numbers..."
. - Otherwise, print
"Error: Division by zero not allowed."
.
- Check if
- Default Case
- Print
"Invalid operation type."
if the number doesn't match any valid case.
- Print
- Return the result of the performed operation.
Example
operationType = 3
, a = 12.0
, b = 4.0
=> "Multiplying numbers..."
and return 48.0
.
Solución
solution.cpp
¡Gracias por tus comentarios!
single