Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int num1,num2,operation;
  6. cout<<"Enter two numbers first and then operand between 0-3 : "<<endl;
  7. cin>>num1>>num2>>operation;
  8. if(cin.fail()){cout<<"Wrong input"<<endl; return 0;}
  9. if((num1>=0 && num1 <=15) && (num2>=0 && num2 <=15 && num2!=0) && operation >=0 && operation <=3)
  10. {
  11. switch (operation){
  12. case 0 : cout<<((num1+num2)%16)<<endl;
  13. break;
  14. case 1 :
  15. {
  16. //dif stands from difference
  17. short dif=num1-num2;
  18. if(dif<0)
  19. dif=dif+16;
  20. cout<<(dif%16)<<endl;
  21. break;
  22. }
  23. case 2 : cout<<((num1*num2)%16)<<endl;
  24. break;
  25. case 3 : cout<<((num1/num2)%16)<<endl;
  26. break;
  27. }
  28.  
  29. }
  30. else cout<<"Wrong input"<<endl;
  31. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement