Challenge: Switch Calculator
Task
Swipe to start coding
Write a function that takes two integers and a character representing an operator (+, -, *, or /). Use a switch statement to perform the corresponding arithmetic operation:
- If the operator is
+, print the sum of the two numbers; - If the operator is
-, print the difference of the two numbers; - If the operator is
*, print the product of the two numbers; - If the operator is
/, print the quotient of the two numbers; - If the operator is not one of the above, or if division by zero is attempted, return zero and print zero.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 9.09
Challenge: Switch Calculator
Swipe to show menu
Task
Swipe to start coding
Write a function that takes two integers and a character representing an operator (+, -, *, or /). Use a switch statement to perform the corresponding arithmetic operation:
- If the operator is
+, print the sum of the two numbers; - If the operator is
-, print the difference of the two numbers; - If the operator is
*, print the product of the two numbers; - If the operator is
/, print the quotient of the two numbers; - If the operator is not one of the above, or if division by zero is attempted, return zero and print zero.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single