Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <cs50.h>
  5.  
  6.  
  7. // declare our global vars that will be shared through out the program's functions
  8. int *digits;
  9. long cardNum;
  10. int firstDigit;
  11. int secondDigit;
  12. int numberOfDigits;
  13. int *evenIndexDigits;
  14. int *oddIndexDigits;
  15.  
  16.  
  17.  
  18. void getInput(void)
  19. {
  20.     // checks input and passes it through a validator, if is valid, return value
  21.     cardNum = get_long("Enter a credit card number: ");
  22.     numberOfDigits = floor(log10(cardNum));
  23.     printf("%d\n", numberOfDigits);
  24.     if (numberOfDigits < 13 || numberOfDigits > 16)
  25.     {
  26.         printf("INVALID check number size!\n");
  27.         exit(0);
  28.     }
  29.     digits = calloc(numberOfDigits, sizeof(int));
  30.     for (int i = 0; i <= numberOfDigits; i++)
  31.     {
  32.         digits[i] = cardNum % 10;
  33.         cardNum /= 10;
  34.     }
  35.    
  36.     firstDigit = digits[0];
  37.     secondDigit = digits[1];
  38. }
  39.  
  40. void parse(void)
  41. {
  42.     numberOfDigits += 1;
  43.     int evenCounter = 0;
  44.     int oddCounter = 0;
  45.     if (numberOfDigits % 2 == 0)
  46.     {
  47.         evenIndexDigits = calloc(8, sizeof(int));
  48.         oddIndexDigits = calloc(8, sizeof(int));
  49.         printf("if worked\n");
  50.        
  51.     }
  52.     else
  53.     {
  54.         evenIndexDigits = calloc(7, sizeof(int));
  55.         oddIndexDigits = calloc(8, sizeof(int));
  56.         printf("else worked\n");
  57.        
  58.     }
  59. }
  60. string checkValidity(void)
  61. {
  62.     return "i dont exist";
  63. }
  64.  
  65.  
  66. int main(void)
  67. {
  68.     getInput();
  69.     //string res = checkValidity();
  70.     parse();
  71.    
  72.  
  73.     free(digits);
  74.     free(evenIndexDigits);
  75.     free(oddIndexDigits);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement