Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Switch Calculator | Conditional Control Flow Practice
C Conditional Statements

bookChallenge: Switch Calculator

Uppgift

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

bookChallenge: Switch Calculator

Svep för att visa menyn

Uppgift

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

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2
single

single

some-alt