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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
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.