Thursday, 6 June 2013

Find arithmetic calculation using switch.

 // WAP to find arithmetic calculation using switch.

#include <iostream>

using namespace std;

int main()
{
float a,b,c;
char o;

cout<<"enter two numbers:  ";
cin>>a>>b;
cout<<"\n enter an operators ('+', '-', '*', '/') ";
cin>>o;
cout<<endl;
switch(o)
{
    case '+': c=a+b;
    break;
    case '-': a-b;
    break;
    case '*': c=a*b;
    break;
    case'/' : if(b==0)
    cout<<"divide by zero is not possible";
    else
    {c=a/b;}
    break;


    default:

    cout<<"wrong input operators"<<endl;
}
    cout<<"Result of given no"<<a<<endl<<b<<"is"<<c;

    return 0;
}
This entry was posted in :

0 comments:

Post a Comment