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

bookChallenge: Switch Calculator

Tehtävä

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.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

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

Pyyhkäise näyttääksesi valikon

Tehtävä

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 2
single

single

some-alt