I'm following C a modern approach and I'm stuck on the "upc.c" exercise. My code looks as follows:
#include <stdio.h>
int main(void)
{
int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5,
first_sum, second_sum, total ;
printf("Enter the first (single) digit: ") ;
scanf("%ld", &d);
printf("Enter first group of five digits: ") ;
scanf("%ld%ld%ld%ld%ld", &i1, &i2, &i3, &i4, &i5) ;
printf("Enter second group of five digits: ") ;
scanf("%ld%ld%ld%ld%ld", &j1,&j2,&j3,&j4,&j5 ) ;
first_sum = d + i2 + i4 + j1 + j3 + j5 ;
second_sum = i1 + i3 + i5 + j2 + j4 ;
total = 3 * first_sum + second_sum ;
printf("Check digit: %d\n", 9-((total - 1) % 10)) ;
return 0;
}
when the input is respectively: 0, 13800 and 15173, the output (check digit) should be 5 but when I try it on my machine the output isn't even a consistent number (but usually around 14/16), so what did I do wrong?