Challenge: Switch Calculator
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 2
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Suggested prompts:
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Fantastisk!
Completion rate forbedret til 9.09
Challenge: Switch Calculator
Sveip for å vise menyen
Oppgave
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.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 2
single