### Converting chars to decimals and vice versa

I'm converting numbers and am confused..My first if works fine..

If i type in A I get back : 10
if i type in B I get back : 11
if i type in C i get back: 12

etc etc..

But If i type in 0-9 i am getting weird numbers, like i type in 5 and get back 1?
And I need to get back 0 the digit.
so I need to be able to put in a 1 and get back 1/
put in a 2 and get back 2.
etc etc
 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include using namespace std; int main(){ char input = ' '; cout << "Enter your number: "; cin >> input; int num = 0; num = input; //If the user types in A, then num will now have the value of 65 in decimal if(input >= 'A' && input <= 'J') { num = input - 'A' + 10; cout << num << endl; } else if(input >= '0' && input <= '9') { input = num + 'A' - 10; cout << input << endl; } else ; system("pause"); }``````
Last edited on
What were you trying to do on line 22?

By the way, the C++ standard does not require the letters to be in order in the character set.
Topic archived. No new replies allowed.