Lynes_Tony_Lab5.c

# Lynes_Tony_Lab5.c - Anthony Lynes Lab5 CSCI 112#include...

• Lab Report
• 1
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1. Sign up to view the full content.

/* * Anthony Lynes * Lab5, CSCI 112 * 3/4/16 */ #include <stdio.h> int sum(int, int[]);//declare sum as 2 arguements, second being an array void Barcode(int *);//assigns pointer 'Barcode' to program void Check(int, int); //this function will sum the even digits int sum(int x, int a[]){ int s=0; for( x=x; x<11; x=x+2){ s=s+a[x]; } return s;} void Barcode(int* a){ //stores barcode into array printf("Enter a barcode to check. Seperate digits with a space >\n"); scanf("%d %d %d %d %d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10], &a[11]); } //this function will check to see if the first digit matches the last //if/else statement will work best for this void Check(int x, int y){ if(x==y){ printf("STEP 5: Check digit and last digit match\n"); printf("Barcode is VALID.\n\n");//tells user digits match } else{ printf("STEP 5: Check digit and last digit do not match\n"); printf("Barcode is INVALID.\n\n");//tells user digits do not match
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: }} //The main function will calculate the steps we need //One each step is calculated, they must be printed int main(void){ int barcode[12];//initializing variables to calculate steps Barcode(barcode); int odds= 3 * sum(0, barcode); int evens= sum(1, barcode); int total= odds + evens; int check= 10 - (total % 10); if(check==10){ check=0; } //print out results to barcode the user entered printf("\nYou entered the code: %d %d %d %d %d %d %d %d %d %d %d %d\n", barcode[0], barcode[1], barcode[2], barcode[3], barcode[4], barcode[5], barcode[6], barcode[7], barcode[8], barcode[9], barcode[10], barcode[11]); printf("STEP 1: Sum of odds times 3 is %d\n", odds);//compute steps printf("STEP 2: Sum of even digits is %d\n", evens); printf("STEP 3: Total sum is %d\n", total); printf("STEP 4: Calculated check digit is %d\n", check); Check(check, barcode[11]);//check barcode return (0);//exit program }...
View Full Document

• Spring '14
• Rafal A. Angryk
• Return statement, Summation, Void type, check digit

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern