I am running below function to do a sumcheck (Luhn's Alrgorithm) on any given card numbers but the check fails on some of the card numbers and also throws up runtime error: "Index out of bounds for type 'int[count]'." I guess this is something about the array being odd/even but unable to figure it out.
Have already tried running the loops to various counts like count+1 and count-1 etc.
int sum1 = 0;
int sum2 = 0;
int count = digit_counter(cc_num);
int hold[count];
for(int i=0; i<count; i++)
{
hold[i]= cc_num%10;
cc_num = cc_num/10;
}
for(int i=0; i<count; i++)
{
printf("%i\n",hold[i]);
}
int i,j;
for (i=1,j=0; i<=count || j<count; i+=2,j+=2)
{
hold[i] = hold[i]*2;
if (hold[i]>10)
{
sum1+= (hold[i]/10)+(hold[i]%10);
}
else
{
sum1+= hold[i];
}
sum2+=hold[j];
}
return sum1+sum2;
Should not throw up any runtime errors and be able to perform the sumcheck on all cards.