Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. void Validation(long long int CardID);
  6. int CardOrder(long long int CardID);
  7.  
  8.  
  9. int main(int argc, string argv[])
  10. {
  11.     long long int CardID = 4276380162463959  ; //15 digit 378282246310005
  12.     Validation(CardID);
  13.        
  14. }
  15.  
  16. int CardOrder(long long int CardID)
  17. {
  18.      for (int i = 0; i <= 20; i++)
  19.          {
  20.              if (CardID/((long long int) pow(10,i)) == 0)
  21.              {
  22.                  return i;
  23.                  break;
  24.              }
  25.          }
  26.     printf("Unknown card ID type");
  27.     return 0;
  28. }
  29.  
  30. void Validation(long long int CardID)
  31. {
  32.     int ValidationValue = 0, temp = 0, Order = CardOrder(CardID), identifier = 0;
  33.    
  34.     for (int i = 1; i <= Order; i++)
  35.     {
  36.         temp = (CardID%(long long int)pow(10,i)/(long long int)pow(10,i-1));
  37.         if (i==Order)
  38.         {
  39.             identifier = temp;
  40.         }
  41.         if (i%2 == 0)
  42.         {
  43.             temp *=2;
  44.             if (temp >= 10)
  45.             {
  46.                 temp = temp/10 + temp%10;
  47.             }
  48.         }      
  49.         ValidationValue += temp;
  50.     }
  51.     printf("Company: ");
  52.     switch (identifier)
  53.     {
  54.         case 3:
  55.             printf("AMEX\n");
  56.             break;
  57.         case 4:
  58.             printf("VISA\n");
  59.             break;
  60.         case 5:
  61.             printf("MASTERSCARD\n");
  62.             break;
  63.         default:
  64.             printf("Unidentified company\n");
  65.     }      
  66.     printf ("ValidationValue: %i\n", ValidationValue);
  67.     if (ValidationValue%10 == 0)
  68.     {
  69.        
  70.         printf ("VALID\n");
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement