11/15/2015

C++ Program For Arithmetic Operations Using Switch Case

Problem:- C++ Program For Arithmetic Operations Using Switch Case or Write A C++ To Perform All Arithmetic Operations Using Switch Case or C++ Program to Make a Simple Calculator Using Switch Case Statement or c++ program to perform arithmetic operations using functions or simple calculator program in c++ or calculator program in c++ using class or c++ program for arithmetic operations using class or scientific calculator program in c++ using switch case or c++ program to perform arithmetic operations using objects and classes or calculator program in c++ using functions or simple calculator program in c++ or c program to perform arithmetic operations using functions

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Logic:- First we are printing the message on screen with 4 options then we are asking for choosing any one of option and after that take two Number form user and pass both number in Switch Case, first write all the cases(for Addition, Subtraction, Multiplication, Division and Mode) then write a code according to statement and execute the operation according to user choice. If you want to see more like this one see C Program To Find The Day Using Switch Case.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.

Solution:-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadav
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;
}

Output:-


No comments:

Post a Comment