Q:

C++ Program For Arithmetic Operations Using Switch Case

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
 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:

Arithmetic Operatios

1.Addition

2.Subtraction

3.Multiplication

4.Division

5.Mode

Enter Your Choice:

3

Enter Two Value Ie:- Value Of A And B100 2000

  Result = 200000

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to Calculate Area of Circle Rectangle ... >>
<< C++ Program To Convert Celsius To Fahrenheit And V...