Ugh, alright, time for more buggy code troubleshooting.
So I wrote this up, compiled just fine and for some reason it will not break out of the first for loop in main()
/*
Program written to verify a 12 digit code from a barcode by comparing the code's last digit to the check digit
Written by Silico Deoxy on November 7, 2015
Version: 1.0
Language: C (gcc target)
*/
#include <stdio.h>
#define SIZE 12
void scan(int upc[]);
int checkodd(int upc[]);
int checkeven(int upc[]);
int main(void){
int upc[SIZE],
i,
f,
sum,
check;
i = 0;
do{
printf("Please enter each digit of the UPC\n");
scanf("%d", &f);
upc = f;
printf("%d\n", i);
i++;
}
while(i<12);
printf("Debug");
sum = checkodd(upc);
sum = sum + checkeven(upc);
if(sum % 10 == 0)
check = 0;
else
check = 10 - (sum % 10);
if(upc[11] == check)
printf("This UPC is correct!");
else
printf("This UPC is incorrect!");
return 0;
}
int checkodd(int upc[]){
printf("Checking odds");
int p,
sum;
sum = 0;
for(p=0;p<12;p+2)
sum = upc[p] + sum;
sum = sum * 3;
return sum;
}
int checkeven(int upc[]){
printf("Checking evens");
int p,
sum;
sum = 0;
for(p=1;p<12;p+2)
sum = upc[p] + sum;
return sum;
}
Can anyone find the problem?