# C# | Design a simple calculator using if else if statements

C# if else if example: Here, we are going to design a simple calculator using if else if conditional statements in C#.
Submitted by Pankaj Singh, on December 25, 2018

The task is to design a simple calculator using if else if statements with following operations:

2. Subtraction
3. Multiplication
4. And, division

Program:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DecisionMaking2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Calculator");
Console.WriteLine("----------------------------");
Console.WriteLine("2.Substract");
Console.WriteLine("3.Multiply");
Console.WriteLine("4.Divide");
Console.Write("Enter Choice(1-4):");
int a, b, c;
if(ch==1)
{
Console.Write("Enter A:");
Console.Write("Enter B:");
c = a + b;
Console.WriteLine("Sum = {0}", c);
}
else if(ch==2)
{
Console.Write("Enter A:");
Console.Write("Enter B:");
c = a - b;
Console.WriteLine("Difference = {0}", c);
}
else if(ch==3)
{
Console.Write("Enter A:");
Console.Write("Enter B:");
c = a * b;
Console.WriteLine("Product = {0}", c);
}
else if(ch==4)
{
Console.Write("Enter A:");
Console.Write("Enter B:");
c = a / b;
Console.WriteLine("Quotient = {0}", c);
}
else
{
Console.WriteLine("Invalid Choice");
}
}
}
}
```

Output

```First run:

Calculator
----------------------------
2.Substract
3.Multiply
4.Divide
Enter Choice(1-4):1
Enter A:10
Enter B:20
Sum = 30

Second run:

Calculator
----------------------------
2.Substract
3.Multiply
4.Divide
Enter Choice(1-4):4
Enter A:10
Enter B:20
Quotient = 0

Third run:

Calculator
----------------------------
2.Substract
3.Multiply
4.Divide
Enter Choice(1-4):5
Invalid Choice
```

What's New (MCQs)

Top Interview Coding Problems/Challenges!

IncludeHelp's Blogs

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates