#include <iostream>
#include <cstdlib>
using namespace std;
// function prototype for add
int add (int x, int y);
int sub (int q, int r);
int mul (int s, int t);
int divi (int u, int v);
int main ()
{
int a,b;
char ch;
loop:cout<<"ENTER CHOICE OF OPERATION: + - OR * / and q to quit";
cout<<'\n';
cin>>ch;
int result;
if(ch!='+'&&ch!='-'&&ch!='*'&&ch!='/'&&ch!='q')
{
cout<<"wrong input";
}
else
{
if(ch=='+')
{
result = add( a, b );
}
else if(ch=='-')
{
result=sub(a,b);
}
else if(ch=='*')
{
result=mul(a,b);
}
else if(ch=='/')
{
result=divi(a,b);
}
else if(ch=='q')
{
exit(0);
}
cout<<"enter 1st number";
cin>>a;
cout<<"enter 2nd number";
cin>>b;
}
cout << "The result is: " << result << '\n';
goto loop;
}
int add (int x, int y)
{
return x + y;
}
int sub (int q, int r)
{
return q-r;
}
int mul (int s, int t)
{
return s*t;
}
int divi (int u, int v)
{
return u/v;
}
Praveen_10 4 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.