It may be a really simple question, but I need to copy two int values that are in array[0] and array[1] into a single integer.
As instance if array[0]=1 and array[1]=6, I need the integer to be equal to “16”.
Any element of the array has a range from 0 to 9.
What chances do I have?
Thank you a lot!
Does array[0] always represent the 10’s place and array[1] always represent the 1’s place? Will array[0] or array[1] ever have a value greater than 9 or less than 0? Will there ever be an array[2] or an array[3] to represent a 3 digit or a 4 digit number?
If the answer to the above questions are Yes, No, and No, then isn’t the answer simple arithmetic?
If the data isn’t pre range-checked, then you’ll need to add that step. Even if the data IS pre range-checked, you should consider adding that step anyway to make extra sure.
’10’ is also a magic number in the above example. It would probably be wise to not hard-code 10, but base it off of the size of the array. Consider the case where there IS an array[2] . . . array[n]. What then?