Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. fail:
  10. int x = 0,y = 0;
  11. char o;
  12. cout <<"Enter two numbers => ";
  13. cin >>x>>o>>y;
  14. while(true)
  15. {
  16. if(cin.fail())
  17. {
  18. cout <<"Error : you are entered a character value ! ..."<<"\n";
  19. cin.clear();
  20. string il;
  21. getline(cin, il);
  22. goto fail;
  23. }
  24. else if(o=='+')
  25. {
  26. cout <<"result = "<<x+y<<"\n";
  27. break;
  28. }
  29. else if(o=='-')
  30. {
  31. cout <<"result = "<<x-y<<"\n";
  32. break;
  33. }
  34. else if(o=='*')
  35. {
  36. cout <<"result = "<<x*y<<"\n";
  37. break;
  38. }
  39. else if(o=='/')
  40. {
  41. cout <<"result = "<<x/y<<"\n";
  42. break;
  43. }
  44. else if(o=='%')
  45. {
  46. cout <<"result = "<<x%y<<"\n";
  47. break;
  48. }
  49. else
  50. {
  51. cout <<"invalid operation ! ..."<<"\n";
  52. break;
  53. }
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement