Merging variables

Hi there. I would like to know if it is possible to merge variables so that if I have 2 variables, a third variable would be variable 1 and 2.

Here is an examle:
int num1 = 5;
int num2 = 8;

int bothNumbers;

How could I make bothNumbers 58?


I know I'm terrible at explaining :)
what do you mean by "merge"?

An integer can only hold 1 number. To do the above example (bothNumbers=58) you could do this:

 
bothNumbers = (num1 * 10) + num2;


But of course that would only work if num1 and num2 are both between [0..9]


You can create a struct which can contain multiple variables:

1
2
3
4
5
6
7
8
9
10
11
struct TwoInts
{
  int a;
  int b;
};

//...

TwoInts bothNumbers;
bothNumbers.a = num1;
bothNumbers.b = num2;


But you'll need to be more clear about what it is you really want.
What I want is exacly what you explained, Thank you :)
Topic archived. No new replies allowed.