Hello, If I have an int array with elements {1,2,3,4}
and I do not want to add the ints inside it but instead I want to have an int variable that holds the first 3 digits of the array for it to be int x = 123; and 123 being the first 3 elements{1,2,3} of the array, any ideas?
Basically instead of having 1 2 3 as separate digits in 3 separate indexes of the array I'd like to have 1 index OR variable that will be 123 as an actual 3 digit number.
if you don't want to (or indeed, can't) use the algorithm then you can write out the equivalent code in long-form:
1 2 3 4 5 6 7 8 9 10
int numberMaker(constint* ar)
{
// return std::inner_product (ar, ar + 3, multipliers, 0);
int number{};
for (size_t i = 0; i < 3; ++i)
{
number += ar[i]*multipliers[i];
}
return number;
}
edit: also need to check that array ar does indeed have at least 3 elements