Simple Calculator Console App Using C#

This app will help end users perform tasks, such as Addition, Subtraction, Multiplication, and Division.

To create the app, follow the steps shown below.

Create a new project

Open the Visual Studio editor. As you can see in the Start Page, there is an option for New Project. Click on “New Project”.

Create a Console Application

The following pop up appears. Select the Console Application. Create the project with name “CalculatorApp”, as shown below. The new project gets created successfully.

Calculator App Code Example

Here is the complete code of the app written in C#. In the program, there are four functional blocks–Addition, Subtraction, Multiplication, and Division. The user has to select one of the options for addition, subtraction, multiplication, and division respectively.

“Press 1 for Addition”.

“Press 2 for Subtraction”.

“Press 3 for Multiplication”.

“Press 4 for Division”.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
namespace CalculatorApp {  
    class Program {  
        static void Main(string[] args) {  
            Console.WriteLine("Enter the action to be performed");  
            Console.WriteLine("Press 1 for Addition");  
            Console.WriteLine("Press 2 for Subtraction");  
            Console.WriteLine("Press 3 for Multiplication");  
            Console.WriteLine("Press 4 for Division \n");  
            int action = Convert.ToInt32(Console.ReadLine());  
            Console.WriteLine("Enter 1st input");  
            int input_1 = Convert.ToInt32(Console.ReadLine());  
            Console.WriteLine("Enter 2nd input");  
            int input_2 = Convert.ToInt32(Console.ReadLine());  
            int result = 0;  
            switch (action) {  
                case 1: {  
                    result = Addition(input_1, input_2);  
                    break;  
                }  
                case 2: {  
                    result = Subtraction(input_1, input_2);  
                    break;  
                }  
                case 3: {  
                    result = Multiplication(input_1, input_2);  
                    break;  
                }  
                case 4: {  
                    result = Division(input_1, input_2);  
                    break;  
                }  
                default:  
                    Console.WriteLine("Wrong action!! try again");  
                    break;  
            }  
            Console.WriteLine("The result is {0}", result);  
            Console.ReadKey();  
        }  
        //Addition  
        public static int Addition(int input_1, int input_2) {  
            int result = input_1 + input_2;  
            return result;  
        }  
        //Substraction  
        public static int Subtraction(int input_1, int input_2) {  
            int result = input_1 - input_2;  
            return result;  
        }  
        //Multiplication  
        public static int Multiplication(int input_1, int input_2) {  
            int result = input_1 * input_2;  
            return result;  
        }  
        //Division  
        public static int Division(int input_1, int input_2) {  
            int result = input_1 / input_2;  
            return result;  
        }  
    }  
}

Output of the Application

Simple Calculator Console App Using C#

In the above example, the user has selected the option “1” to perform addition. Then, the app asks the user to provide two inputs. After entering the inputs, the addition operation is performed and the user gets the desired output.

Likewise, the user has to choose the different options to perform different tasks.