Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <math.h>
- void Validation(long long int CardID);
- int CardOrder(long long int CardID);
- int main(int argc, string argv[])
- {
- long long int CardID = 4276380162463959 ; //15 digit 378282246310005
- Validation(CardID);
- }
- int CardOrder(long long int CardID)
- {
- for (int i = 0; i <= 20; i++)
- {
- if (CardID/((long long int) pow(10,i)) == 0)
- {
- return i;
- break;
- }
- }
- printf("Unknown card ID type");
- return 0;
- }
- void Validation(long long int CardID)
- {
- int ValidationValue = 0, temp = 0, Order = CardOrder(CardID), identifier = 0;
- for (int i = 1; i <= Order; i++)
- {
- temp = (CardID%(long long int)pow(10,i)/(long long int)pow(10,i-1));
- if (i==Order)
- {
- identifier = temp;
- }
- if (i%2 == 0)
- {
- temp *=2;
- if (temp >= 10)
- {
- temp = temp/10 + temp%10;
- }
- }
- ValidationValue += temp;
- }
- printf("Company: ");
- switch (identifier)
- {
- case 3:
- printf("AMEX\n");
- break;
- case 4:
- printf("VISA\n");
- break;
- case 5:
- printf("MASTERSCARD\n");
- break;
- default:
- printf("Unidentified company\n");
- }
- printf ("ValidationValue: %i\n", ValidationValue);
- if (ValidationValue%10 == 0)
- {
- printf ("VALID\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement