Calculator program in C#

A simple calculator application in console to perform various mathematical operation in C#. This program for beginner programmer. After learning this program you can add your own logics.

Source code - Calculator Program in Console(C#).

	
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            float c;
            int choice;
            //Calculator Program in Console
            Console.WriteLine("======== CALCULATOR PROGRAM FOR BEGINER ==========");
            Console.WriteLine(" :::::::::::::::CALCULATION OPERATION.::::::::::::");
            Console.WriteLine("1. ABSTRACT OPERATION(+).");
            Console.WriteLine("2. SUBTRACT OPERATION(-).");
            Console.WriteLine("3. MULTIPLY OPERATION(*).");
            Console.WriteLine("4. DIVIDE OPERATION(/).");
            Console.WriteLine("5. EXIT THE APPLICATION.");

            Console.WriteLine("\nENTER YOUR FIRST NUMBER:- ");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("ENTER YOUR SECOND NUMBER:- ");
            b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\nENTER YOUR CHOICE:- ");

            choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
                case 1:
                    c = a + b;
                    Console.WriteLine("Result Is :- " + c);
                    break;
                case 2:
                    c = a - b;
                    Console.WriteLine("Result Is :- " + c);
                    break;
                case 3:
                    c = a * b;
                    Console.WriteLine("Result Is :- " + c);
                    break;
                case 4:
                    c = a / b;
                    Console.WriteLine("Result Is :- " + c);
                    break;
                case 5:
                    Environment.Exit(5);
                    break;
            }
            Console.ReadLine();
        }
    }
}
	

Output

	
   ======== CALCULATOR PROGRAM FOR BEGINER ==========
   :::::::::::::::CALCULATION OPERATION.::::::::::::
   1. ABSTRACT OPERATION(+).
   2. SUBTRACT OPERATION(-).
   3. MULTIPLY OPERATION(*).
   4. DIVIDE OPERATION(/).
   5. EXIT THE APPLICATION.
   
   ENTER YOUR FIRST NUMBER :-
   5
   ENTER YOUR SECOND NUMBER :-
   10
   ENTER YOUR CHOICE :-
   1
   Result Is :- 15
    
Advertisement here

Share this Page.