Question: Simple calculator Given two integer numbers N1, N2 and an operation character C. Write a simple calculator which performs the 4 basic mathematical operations (i.e.

Simple calculator

Given two integer numbers N1, N2 and an operation character C. Write a simple calculator which performs the 4 basic mathematical operations (i.e. Addition, Subtraction, Multiplication, and Division) according to given character C.

Hint: Use type-casting Write a function solution that accepts two integers N1, N2 and an operation character C. The function should return the operation result based on the character supplied. For N1 = 5, N2 = 10 and C = +, calculated result will be 5 + 10 = 15. Note if C is not a valid operator then return -1. if C is '/' (division) and N2 = 0 (zero) then return -2.

Below is the partial code

using System;

public class ProblemSolution

{

//Do not use standard input/ouput methods like Console.WriteLine()/Console.ReadLine().

public double solution (int N1, int N2, char C) {

//write your code here

}

class DriverMain{

//Your program will be evaluated by this main method and several test cases.

public static void Main () {

int N1, N2; char C; double result;

ProblemSolution problemsolution=new ProblemSolution();

N1 = int.Parse (Console.ReadLine ());

N2 = int.Parse (Console.ReadLine ());

C = Convert.ToChar (Console.ReadLine ());

result = problemsolution.solution (N1, N2, C); Console.Write ($"{result:0.00##}");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!