Calculate the sum of the digits in the odd-numbered position

Assignment Help Computer Engineering
Reference no: EM132087382

Overview

For this lab, you will write a program that prompts the user to enter the 12 digits of a UPC barcode, which you will store in an array. Using the algorithm described below, you will determine if the barcode is valid or invalid.

Algorithm

A barcode scanner for Universal Product Codes (UPC) verifies the 12-digit code scanned by comparing the code's last digit (called a check digit) to its own computation of the check digit from the first 11 digits. The process of validating a barcode is described below.

Calculate the sum of the digits in the odd-numbered position (first, third, ..., eleventh). Multiply this sum by three.

NOTE: In C arrays, we count array indices starting at 0. Therefore, the "first" digit of the barcode will be stored in the 0th position of your array. Be careful to manage your array indices correctly.

Calculate the sum of the digits in the even numbered positions (second, fourth, ..., tenth) of the barcode.

NOTE: Remember, the 12th digit of the barcode is the checksum. Make sure not to include it in your sum of even indices.

Add these two sums together.

From this combined sum, extact the last digit. If the last digit is a 0, then 0 is the check digit. Otherwise, subtract the last digit from 10 to calculate the check digit.

NOTE: To extract an individual digit from a number, use the % modulus operator

If the check digit matches the final digit of the 12-digit UPC, the UPC is valid. If not, the UPC is invalid.

Program

Write a program that prompts the user to enter the 12 digits of a barcode, separated by spaces. Your program will store the digits in an integer array, calculate the check digit, and compare your calculated check digit to the final barcode digit (the true check digit). If the digits match, the barcode is valid. Otherwise the barcode is invalid. You will print out your intermediate calculations for each step (1-5). See the Example Execution section to determine how to format your results.

TIP: Practice good program design by splitting your program into subtasks and write a functoin to solve each subtask. Do not write all of your code in your main function.

Example Execution

[esus] $ ./lab5 Enter a bar code to check. Separate digits with a space > 0 7 9 4 0 0 8 0 4 5 0 1 You entered the code: 0 7 9 4 0 0 8 0 4 5 0 1 STEP 1: Sum of odds times 3 is 63 STEP 2: Sum of the even digits is 16 STEP 3: Total sum is 79 STEP 4: Calculated check digit is 1 STEP 5: Check digit and last digit match Barcode is VALID. [esus] $ ./lab5 Enter a bar code to check. Separate digits with a space > 0 2 4 0 0 0 1 6 2 8 6 0 You entered the code: 0 2 4 0 0 0 1 6 2 8 6 0 STEP 1: Sum of odds times 3 is 39 STEP 2: Sum of the even digits is 16 STEP 3: Total sum is 55 STEP 4: Calculated check digit is 5 STEP 5: Check digit and last digit do not match Barcode is INVALID.
Compile & Test

Compile your program using this gcc command. c99 is a shortcut for running gcc -std=c99, which uses the C99 standard instead of the default C89 standard.

$ c99 -Wall lab5.c -o lab5
Self Check

One you finish, you can test out your program with the following barcodes.

0 7 9 4 0 0 8 0 4 5 0 1 Valid 0 1 1 1 1 0 8 5 6 8 0 7 Valid 0 5 1 0 0 0 1 3 8 1 0 1 Valid 0 2 4 0 0 0 1 6 2 8 6 0 Invalid

These barcodes are provided to allow you to verify that your program is working correctly.

Reference no: EM132087382

Questions Cloud

Determine how many of each item should be ordered : Imagine that you are a merchant and need to keep better tabs on your merchandise to know when to reorder supplies.
Nodes of ranvier in a myelinated nerve : What would happen if you lost the nodes of Ranvier in a myelinated nerve? Would the message travel faster, slower
Write a program that will find several trait of a collection : Write a program that will find several traits of a collection of NN numbers. Get the value of NN before scanning each value in the collection of NN numbers.
Why do pain receptors do not undergo adaptation : Why do pain receptors do not undergo adaptation, but other receptor types do?
Calculate the sum of the digits in the odd-numbered position : Calculate the sum of the digits in the odd-numbered position (first, third, ..., eleventh). Multiply this sum by three.
Develop a portfolio of draft planning documentation : BSBPMG522 Undertake project work Assignment - You will determine the scope of a project and develop a portfolio of draft planning documentation
Can you find illusions for other senses : Why is it easier to fool the eyes, compared to fooling to your sense of touch? Can you find illusions for other senses? How do they work?
Complete a wireless network design for a small company : Complete a wireless network design for a small company. You will place a number of network elements on the diagram and label them appropriately.
Inflamed facial nerve : A woman is admitted to the hospital with Bell's palsy caused by an inflamed facial nerve. What symptoms will you, as the attending physician

Reviews

Write a Review

Computer Engineering Questions & Answers

  Create an oracle for this function

a sub-graph G'(V',E') of G such that for any two nodes u,v in V', there is an edge e=(u,v) in E'. In addition, G' should be the maximum in terms of size. That is, for any other G'' with the above property, we have |G''| no larger than |G'|.

  Create virtual machines so that they can test applications

You are an administrator for the Contoso Corporation and you are responsible for multiple Hyper-V hosts. Often, the developers need to create virtual machines so that they can test their applications.

  Strategic applications of information technology

Strategic applications of information technology, Prepare a final report

  What is the minimum number of states of a dfa

Let Ln be a collection of words over {0, 1} that begin with precisely n zeros. What is the minimum number of states of a DFA that recognizes Ln?

  Consider whether there should be a hard

normally , we use normalization techniques a database. using the bowen et al. (2004) article, discuss the disadvantages of normalizing the database to a high degree of normalization.

  Developing the database of company

Enable the user in order to input a last name; then find the file and show all the names and phone numbers corresponding to that last name.

  Determining the format of the number to be entered first

Determining the format of the number to be entered first - If the number entered cannot be expressed as 8 or 16 bits according to the selected bit value, the program - The sign bit varies depending on whether the count is positive or negative.

  Which type of network application require elaborate software

Which type of network application requires more elaborate software: connection oriented or connectionless? Explain.

  List some applications for large-screen displays

Explain how viflual-reality systems can be used in design applications. List some applications for large-screen displays.

  Why td updates are likely to be much better

Can you see why TD updates are likely to be much better, at least initially, in this case? Might the same sort of thing happen in the original task?

  Explain the use of microsoft baseline security analyzer

Your draft guidance will explain the use of Windows Defender and Microsoft Baseline Security Analyzer and then describe how each could be used as part of an inc

  Make a plan to deploy several visual basic.net

Your supervisor has asked you to develop a plan to deploy several Visual Basic.NET applications to users in your company. Discuss the important considerations in this effort and give a summary of the technical approach you would use to deploy thes..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd