#include #include void main(void) { char upc[12]; int eventotal=0,oddtotal=0,lastnumbertotal=0; int x=0,intcheck=-1; cout << "Enter a UPC number: "; cin >> upc; cout << endl << endl; if(strlen(upc)<=10){ cout << "You entered " << strlen(upc) << " digits." << endl; cout << "It isn't enough to do any calculations." << endl; exit(0); } if(strlen(upc)==11){for(x=strlen(upc); x<13; x++){upc[x]='0';}} //Odd add cout << "Odd numbers (positions 1,3,5,etc.): "; for(x=0;x<=11;x+=2) { oddtotal+=(int)upc[x]-48; cout << upc[x] << " "; } cout << endl; //Even add cout << "Even numbers (positions 2,4,6,etc): "; for(x=1;x<=10;x+=2) { eventotal+=(int)upc[x]-48; cout << upc[x] << " "; } cout << endl << endl; cout << "The odd number total: " << oddtotal << endl; cout << "The even number total: " << eventotal << endl << endl; oddtotal*=3; lastnumbertotal=oddtotal+eventotal; for(x=0; x<10; x++){ intcheck=(lastnumbertotal+x)/10.0; if(intcheck==(lastnumbertotal+x)/10.0){break;} } if((int)upc[11]-48!=0){ cout << "The entered check digit: " << (int)upc[11]-48 << endl; cout << "Calculated check digit: " << x << endl << endl; if((int)upc[11]-48==x){cout << "They are equal! The barcode is good." << endl;} else {cout << "They are not equal. The barcode is bad." << endl;} } else { cout << "The check digit was not entered." << endl; cout << "Calculated last number of the UPC: " << x << endl << endl; } }