Question
Using C Programming For this project, you will implement a function that validates Visa credit card numbers. The function will take an unsigned long long
Using C Programming
For this project, you will implement a function that validates Visa credit card numbers. The function will take an unsigned long long int and return an int (or bool). A file is provided for you to complete. You only need to implement the function. You must match the function prototype given. You will receive a 0 if your function implementation does not match the given prototype. Do not add any global variables.
A valid Visa credit card has the following properties:
- starts with a 4
- is 16 digits long
- the Luhn algorithm results in a value that is a multiple of 10 (value % 10 = 0)
Here is a description of the Luhn algorithm using the number 4388576018402626.
- Starting with the rightmost digit, add every other digit.
6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
- Double every other digit starting with the second digit from the right. If doubling of a digit results in a two-digit number, add the two digits to get a single-digit number.
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
Add all the single digit numbers.
4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37
- Sum the results from Steps 2 and 3.
38 + 37 = 75
- If the result from step 3 is divisible by 10, the credit card number is valid. Otherwise the number is invalid.
Use the below code to start:
#include
int isValidCC(unsigned long long int CCNumber);
int main()
{
unsigned long long int CCNumbers[] = {
4388576018410707ULL, // valid
4388576018402626ULL, // invalid
7388576018402686ULL, // invalid
438857601810707ULL, // invalid
4012888888881881ULL // valid
};
for (int i = 0; i < sizeof(CCNumbers) / sizeof(CCNumbers[0]); i++)
{
if (isValidCC(CCNumbers[i]))
{
printf("%llu is a valid Visa number. ", CCNumbers[i]);
}
else
{
printf("%llu is not a valid Visa number. ", CCNumbers[i]);
}
}
}
int isValidCC(unsigned long long int CCNumber)
{
// TO DO
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started