-
Notifications
You must be signed in to change notification settings - Fork 0
/
credit.c
60 lines (47 loc) · 1019 Bytes
/
credit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<stdlib.h>
#include<cs50.h>
int main(void){
long long ccNumber;
int sum1;
int sum2;
int total;
int current;
int digits = 0;
int fd;
ccNumber = get_long_long("Number: ");
long long temp = ccNumber;
while(temp > 0){
if(temp < 100 && temp > 10)
fd = temp;
temp = temp / 10;
digits++;
}
temp = ccNumber;
temp = temp/10;
sum1 = 0;
while(temp > 0){
current = (temp % 10) * 2;
if(current > 9){
sum1 = sum1 + (current%10) + ((current/10)%10);
}
else sum1 = sum1 + current;
temp = temp / 100;
}
temp = ccNumber;
sum2 = 0;
while(temp > 0){
current = temp %10;
sum2 = sum2 + current;
temp = temp /100;
}
total = sum1 + sum2;
if(total % 10 == 0 && (fd == 34 || fd == 37) && digits == 15)
printf("AMEX\n");
else if(total % 10 == 0 && (fd >=51 && fd <= 55) && digits == 16)
printf("MASTERCARD\n");
else if(total % 10 == 0 && (fd > 39 && fd < 50) && (digits == 13 || digits == 16))
printf("VISA\n");
else
printf("INVALID\n");
}