03/03/2023

C++ Program to Perform Arithmetic Operations Using Switch Case

Write a C++ program for addition, subtraction, multiplication and division using switch case or write a program to perform arithmetic operations using switch case in C++. First, we are printing the message on-screen with 4 options then we are asking for choosing any one of the options after that take two Numbers from the user and pass both numbers into the Switch Case. First write all the cases(for Addition, Subtraction, Multiplication, Division and Mode).

C++ Program to Perform Arithmetic Operations Using Switch Case

Write a code according to the statement and execute the operation according to the user's choice. We can also use these programming statements as a C++ program to make a simple calculator to add, subtract, multiply or divide using a switch case.

C++ Program to Perform Arithmetic Operations Using Switch Case


#include <iostream>
using namespace std;
int main()
{
	/*C++ program for addition, subtraction, multiplication and division using switch case */
	float a, b, rem;
	int ch, q;

	cout << "Arithmetic Operatios";
	cout << "\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Mode";
	cout << "\n\nEnter Your Choice:\n";
	cin >> ch;

	switch (ch)
	{
		case 1:
			{
				cout << "\nEnter Two Value Ie:- Value Of A And B ";
				cin >> a >> b;
				rem = a + b;
				cout << "\n  Result = " << rem;
				cout << "\n";
			}

			break;

		case 2:
			{
				cout << "\nEnter Two Value Ie:- Value Of A And B";
				cin >> a >> b;
				rem = a - b;
				cout << "\n  Result = " << rem;
				cout << "\n";
			}

			break;

		case 3:
			{
				cout << "\nEnter Two Value Ie:- Value Of A And B";
				cin >> a >> b;
				rem = a * b;
				cout << "\n  Result = " << rem;
				cout << "\n";
			}

			break;

		case 4:
			{
				cout << "\nEnter Two Value Ie:- Value Of A And B";
				cin >> a >> b;

				if (a >= b)
				{
					rem = a / b;
					cout << "\n  Result = " << rem;
					cout << "\n";
				}
				else
					cout << "\nt 1st Varable Should Be Greater Than 2nd.  !!!";
				cout << "\n";
			}

			break;

		case 5:
			{
				cout << "\nEnter Two Value Ie:- Value Of A And B";
				cin >> a >> b;
				if (a >= b)
				{
					q = a / b;
					rem = a - (b *q);
					cout << "\n  Result = " << rem;
					cout << "\n";
				}
				else
					cout << "\nt 1st Varable Should Be Greater Than 2nd.  !!!";
				cout << "\n";
			}

			break;
	}

	return 0;
}

The Output of Arithmetic Operations Program in C++


The Output of Arithmetic Operations Program in C++

Similar to Arithmetic Operations


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: