Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int charToHex(char helper)
  6. {
  7. if (helper > 47 || helper < 48)
  8. {
  9. return helper - 48;
  10. }
  11. else if (helper > 64 || helper < 71)
  12. {
  13. return helper - 55;
  14. }
  15. return -1;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. char operation;
  22. char firstNumChar;
  23. char secondNumChar;
  24.  
  25. cin >> operation >> firstNumChar >> secondNumChar;
  26.  
  27. int firstNumInt = charToHex(firstNumChar);
  28. int secondNumInt = charToHex(secondNumChar);
  29.  
  30. int result;
  31.  
  32. if (operation == '+')
  33. result = firstNumInt + secondNumInt;
  34. if (operation == '-')
  35. result = firstNumInt - secondNumInt;
  36. if (operation == '*')
  37. result = firstNumInt * secondNumInt;
  38. if (operation == '/')
  39. {
  40. if (secondNumInt != 0)
  41. {
  42. result = firstNumInt / secondNumInt;
  43. }
  44. else
  45. {
  46. cout << "Wrong input" << endl;
  47. }
  48. }
  49. if (operation == '%')
  50. {
  51. if (secondNumInt != 0)
  52. {
  53. result = firstNumInt % secondNumInt;
  54. }
  55. else
  56. {
  57. cout << "Wrong input" << endl;
  58. }
  59. }
  60.  
  61. if (result <= 9)
  62. {
  63. cout << result;
  64. }
  65. else if (result >= 10 && result <= 15)
  66. {
  67. result= result + 55;
  68. }
  69. else if (result >= 16)
  70. {
  71. int helperOneInt = 0;
  72. int helperTwoInt = 0;
  73.  
  74. helperOneInt = result % 16;
  75. if (helperOneInt > 16)
  76. {
  77. helperTwoInt = (helperOneInt / 16) % 16;
  78. }
  79.  
  80. if ()
  81.  
  82.  
  83.  
  84. cout << charToHex(result) << endl;
  85.  
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement