How to parse a series of concatenated digits into one number?

This is the partial code of a project I'm building:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
                        int fourkey = console.getkeypress();
                        switch(fourkey){
                            case '0': fourkey = 0; break;
                            case '1': fourkey = 1; break;
                            case '2': fourkey = 2; break;
                            case '3': fourkey = 3; break;
                            case '4': fourkey = 4; break;
                            case '5': fourkey = 5; break;
                            case '6': fourkey = 6; break;
                            case '7': fourkey = 7; break;
                            case '8': fourkey = 8; break;
                            case '9': fourkey = 9; break;

                            return fourkey;
                        }
                        console.clearscreen();
                        cout << setw(7) << zerokey;
                        cout << onekey; /*goto and clearscreen*/
                        cout << secondkey;
                        cout << thirdkey;
                        cout << fourkey;


As you can see at the end there are several digits which are printed onto the console, for example, let's say onekey is equivalent to 1, secondkey equivalent to 2, the thirdkey equivalent to 3 and the fourkey equivalent to 4. This would obviously print: 1234. But these are only concatenated digits not a number. So how can I convert these concatenated digits into a number? In this case, one thousand, two hundred and thirty four.

I would greatly appreciate any help!
You mean 1000*onekey+100*secondkey+10*thirdkey+fourkey ?

By the way, note that a conversion from '1' to 1 and etc. can be done by subtracting '0'. You don't need a switch.
Topic archived. No new replies allowed.