# Introduction to Programming - 18390

Request Posted by

## tommytin8822

Rating : No Rating
• Requests:0
• Solutions:0
Earned: \$0
Request Detail
Price: \$10
• From: Computer Science, Programming
• Due on: Sun 14 Jul, 2013 (07:30am)
• Asked on: Sun 14 Jul, 2013
• Due date has passed, but you can still Post Solution.
Description
Final Project — Topic 2
Credit Card Number
The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, we will describe it for numbers with 8 digits instead of 16.
Step 1. Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is 43589795, then you form the sum 5 + 7 + 8 + 3 = 23
Step 2. Double each of the digits that are not included in the preceding step. Add all digits of the resulting numbers. For example, with the number given above, doubling the digits, starting with the next –to-last one, yields 18 18 10 8. Adding all digits in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27
Step 3. Add the sums of the two preceding steps. If the last digit of the result is 0, the number is valid. In our case, 23 + 27 = 50, so the number is valid.
Write a program that implements this algorithm. The user should supply an 8-digit number, and you should print out whether the number is valid or not.
Extra credit
1. If the number is not valid, you should print out the value of the check digit that would make the number valid. For example, if the number entered by the user is 43589796, the sum of first two steps is 51, so the number is invalid. You should print out 5 as the correct value of the check digit that can make the number valid.
(1) Ask the user whether he/she want to check another number. If the user answers “Yes”, then
the previous procedure should repeat. If the user enters “No”, the program should terminate.
(2) Let the program randomly generate an 8-digit number. Then, it displays the number and whether the number is valid or not.
(3) Let the user choose whether the an 8-digit number should be random generated by the program or input by the user
1 Solution for Introduction to Programming
Title Price Category solution By purchased
Solution to this problem
\$10.00 no category sagar1992 0 time(s)