Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int num1,num2,operation;
- cout<<"Enter two numbers first and then operand between 0-3 : "<<endl;
- cin>>num1>>num2>>operation;
- if(cin.fail()){cout<<"Wrong input"<<endl; return 0;}
- if((num1>=0 && num1 <=15) && (num2>=0 && num2 <=15 && num2!=0) && operation >=0 && operation <=3)
- {
- switch (operation){
- case 0 : cout<<((num1+num2)%16)<<endl;
- break;
- case 1 :
- {
- //dif stands from difference
- short dif=num1-num2;
- if(dif<0)
- dif=dif+16;
- cout<<(dif%16)<<endl;
- break;
- }
- case 2 : cout<<((num1*num2)%16)<<endl;
- break;
- case 3 : cout<<((num1/num2)%16)<<endl;
- break;
- }
- }
- else cout<<"Wrong input"<<endl;
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement