Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++

#incldue <iostream>


void multiply(int x, int y)
{
  return x*y;
}


void divide(int x, int y)
{
  return x/y;
}

void add(int x, int y) 
{
  return x+y;
}

void subtract(int x, int y)
{
  return x-y;
}


using namespace std;

int main()
{
  string op='c';
  int x, y;
  while(op!='e')
  {
  cout<<"What operation would you like to perform: add(+), subtract(-), divide(/), 
  multiply(*), [e]xit?";
  cin>>op;
  switch(op)
  {
    case 1: '+':
    cin>>x;
    cin>>y;
    cout>>x>>"+">>y>>"=">>add(x, y)>>endl_
    break;
    case 2: '-':
    cin>>x;
    cin>>y;
    cout<<x<<"-"<<y<<"="<<subtract(x, y)<<endl;
    break;
    case 3: '/':
    cin>>x;
    cin>>y;
    cout<<x<<"/"<<y<<"="<<divide(x, y)<<endl;
    break;
    case 4: '*':
    cin>>x;
    cin>>y;
    cout<<x<<"*"<<y<<"="<<multiply(x, y)<<endl;
    break;
    case 'e':
    return 0;
    default:
    cout<<"Sorry, try again"<<endl;
    }
  }
  return 0;
}
Solution
Source by www.cprogramming.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
5+9 =