Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Simple Calculator | Functions with Different Signatures
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Methods & Modular Thinking

bookChallenge: Simple Calculator

Tarefa

Swipe to start coding

Create a method that performs a basic calculation based on the given operation. The method should accept two integers and a string that specifies the operation to perform.

  • If the operation is "add", return the sum of the two numbers.
  • If the operation is "subtract", return the difference of the two numbers.
  • If the operation is "multiply", return the product of the two numbers.
  • If the operation is "divide", return the integer division result of the two numbers. If the second number is zero, throw an ArgumentException with the message "Cannot divide by zero.".
  • If the operation is not one of the specified options, throw an ArgumentException with the message "Invalid operation.".

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain this in simpler terms?

What are the main benefits or drawbacks?

Can you give me a real-world example?

close

bookChallenge: Simple Calculator

Deslize para mostrar o menu

Tarefa

Swipe to start coding

Create a method that performs a basic calculation based on the given operation. The method should accept two integers and a string that specifies the operation to perform.

  • If the operation is "add", return the sum of the two numbers.
  • If the operation is "subtract", return the difference of the two numbers.
  • If the operation is "multiply", return the product of the two numbers.
  • If the operation is "divide", return the integer division result of the two numbers. If the second number is zero, throw an ArgumentException with the message "Cannot divide by zero.".
  • If the operation is not one of the specified options, throw an ArgumentException with the message "Invalid operation.".

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

some-alt