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

bookChallenge: Simple Calculator

Aufgabe

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.".

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 4
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

close

bookChallenge: Simple Calculator

Swipe um das Menü anzuzeigen

Aufgabe

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.".

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 4
single

single

some-alt