diff options
| author | mo <mo.khan@gmail.com> | 2019-06-06 20:57:16 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-06-06 20:57:16 -0600 |
| commit | f071592d77d136e90ad481a4e1a5bc11a5f52026 (patch) | |
| tree | 87110d6833c28dd83d27e65caf4fd6cc698c281e /src/Q3/README.md | |
| parent | 5bee7906945f8e586482dac86d3de6c89b88017c (diff) | |
start Q3
Diffstat (limited to 'src/Q3/README.md')
| -rw-r--r-- | src/Q3/README.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Q3/README.md b/src/Q3/README.md new file mode 100644 index 0000000..6f6ab07 --- /dev/null +++ b/src/Q3/README.md @@ -0,0 +1,42 @@ +Learning Profile for Assignment #2, And Question #3 + +Name: Mo Khan +Student ID: 3431709 + +1. Problem Statement: + +```text +Credit card numbers follow certain patterns. +A credit card number must have between 13 and 16 digits. +It must start with 4 for Visa cards, 5 for Master cards, 37 for American Express cards, and 6 for Discover cards. +In 1954, Hans Luhn of IBM proposed the following algorithm for validating credit card numbers: +* a. Double every second digit from right to left (e.g., if number is 3 => 3 * 2 => 6) and add them together. +* b. If this doubling results in a two-digit number, then add the two digits to get a single-digit number (e.g., if number is 5 => 5 * 2 => 10 => 1+0 => 1). + +So, for the credit card number 4388576018402626, doubling all second digits from the right results in + +```text + (2 * 2 = 4) + (2 * 2 = 4) + (4 * 2 = 8) + (1 * 2 = 2) + (6 * 2 = 12 = 1 + 2 = 3) + (5 * 2 = 10 = 1 + 0 = 1) + (8 * 2 = 16 = 1 + 6 = 7) + (4 * 2 = 8). +``` + +This totals to 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37. + +Add all digits in the odd places from right to left. +The leftmost digit of the credit card number is at index 0; + +6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38. + +Add results from steps (a) and (b) and see if divisible by 10. +If it is, then the card number is valid; otherwise invalid. + +37 + 38 = 75 is not divisible by 10, so it is an invalid credit card number. + +Implement Luhn’s algorithm in a program to determine whether a given credit card number is valid or not. +You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn’s algorithm to test its validity, +and if it is valid, print the name of the company that offers that credit card number. +``` + +2. Description of the Code: +3. Errors and Warnings: +4. Sample Input and Output: +5. Discussion: |
