-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredit.c
More file actions
97 lines (65 loc) · 1.74 KB
/
credit.c
File metadata and controls
97 lines (65 loc) · 1.74 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <cs50.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
int main(void)
{
int sum1, sum2, sum = 0;
int num ;
long number;
do
{
number = get_long("Please Enter Credit Card number : "); // for user input cc number.
}
while (number <= 0);
/// For oddly place numbers.
long workingccnum = number ;
while (workingccnum > 0)
{
int lastdigit = workingccnum % 10; // get the last number.
sum = sum + lastdigit;
workingccnum = workingccnum / 100 ; /// get the second number to add to last number.
}
/// For evenly place numbers.
workingccnum = number / 10 ;
while (workingccnum > 0)
{
int lastdigit = workingccnum % 10; /// get the last number.
int twiceddigits = lastdigit * 2;
sum = sum + (twiceddigits % 10) + (twiceddigits / 10) ; /// Add the numbers
workingccnum = workingccnum / 100 ; /// update the working number.
}
if (sum % 10 == 0) /// chechsum .
{
num = true;
}
else
{
num = false;
}
if (num == true && number >= 4000000000000 && number <= 4999999999999)
{
printf("VISA\n");
}
else if (num == true && 340000000000000 <= number && number <= 349999999999999)
{
printf("AMEX\n");
}
else if (num == true && 370000000000000 <= number && number <= 379999999999999)
{
printf("AMEX\n");
}
else if (num == true && number >= 400000000000000 && number <= 4999999999999999)
{
printf("VISA\n");
}
else if (num == true && number >= 5100000000000000 && number <= 5599999999999999)
{
printf("MASTERCARD\n");
}
else
{
printf("INVALID\n");
}
return 0;
}