Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int charToHex(char helper)
- {
- if (helper > 47 || helper < 48)
- {
- return helper - 48;
- }
- else if (helper > 64 || helper < 71)
- {
- return helper - 55;
- }
- return -1;
- }
- int main()
- {
- char operation;
- char firstNumChar;
- char secondNumChar;
- cin >> operation >> firstNumChar >> secondNumChar;
- int firstNumInt = charToHex(firstNumChar);
- int secondNumInt = charToHex(secondNumChar);
- int result;
- if (operation == '+')
- result = firstNumInt + secondNumInt;
- if (operation == '-')
- result = firstNumInt - secondNumInt;
- if (operation == '*')
- result = firstNumInt * secondNumInt;
- if (operation == '/')
- {
- if (secondNumInt != 0)
- {
- result = firstNumInt / secondNumInt;
- }
- else
- {
- cout << "Wrong input" << endl;
- }
- }
- if (operation == '%')
- {
- if (secondNumInt != 0)
- {
- result = firstNumInt % secondNumInt;
- }
- else
- {
- cout << "Wrong input" << endl;
- }
- }
- if (result <= 9)
- {
- cout << result;
- }
- else if (result >= 10 && result <= 15)
- {
- result= result + 55;
- }
- else if (result >= 16)
- {
- int helperOneInt = 0;
- int helperTwoInt = 0;
- helperOneInt = result % 16;
- if (helperOneInt > 16)
- {
- helperTwoInt = (helperOneInt / 16) % 16;
- }
- if ()
- cout << charToHex(result) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement