Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * credit.c
- *
- * Jody W Moore
- *
- * this program takes in a credit card number
- * and returns VALID or INVALID number.
- *
- **/
- #include <cs50.h>
- #include <math.h>
- #include <stdio.h>
- int main(void)
- {
- long long num = 0;
- int digit = 0;
- int odd = 0;
- int ctr = 0;
- int prod = 0;
- int prod2 = 0;
- int cheksum = 0;
- int validater = 0;
- int even = 0;
- int id1 = 0;
- // promt user for credit card # using GetLongLong
- do
- {
- printf("Number: ");
- num = GetLongLong();
- }
- while(num <= 0);
- while (num > 0 )
- {
- digit = num % 10;
- num = num / 10;
- ctr++;
- if ( ctr != 0 )
- {
- odd = digit + odd;
- }
- if ( ctr == 0 )
- {
- prod = digit * 2 ;
- if (prod <= 9)
- {
- even = even + prod;
- }
- else
- {
- int temp_num = prod % 10;
- prod2 = temp_num + 1;
- even = even + prod2 ;
- }
- }
- }
- id1 = digit;
- cheksum = even + odd;
- validater = cheksum % 10;
- if ( validater != 0)
- {
- printf("INVALID\n");
- }
- else
- {
- if ( id1 == 3 )
- {
- printf("AMEX\n");
- }
- else if ( id1 == 4 )
- {
- printf("VISA\n");
- }
- else if (id1 == 5 )
- {
- printf("MASTERCARD\n");
- }
- else if ( id1 == 6)
- {
- printf("Discover\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement