I just finished solving the credit problem and regularly used check50 to see my results, and then this happened. check50 sees that these numbers :
369421438430814
5673598276138003
are invalid, even though in every luhn calculator on the internet these numbers are valid ps:// I will leave links for the luhn calculator at the end of the post. ps2:// tried my code with every one of Paypal suggested credit cards and it works perfectly. ps3:// my code included at the end of the post just in case.
site1:https://goodcalculators.com/luhn-algorithm-calculator/?Num=4012888888881881 site2:https://www.dcode.fr/luhn-algorithm site3:https://www.mymathtables.com/numbers/luhn-algorithm-calculator.html
#include <cs50.h>
#include <stdio.h>
#include <math.h>
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>The
Start Of The
Program<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
int main(void)
{
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|||||| Define
variables Section ||||||<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
long long credit_card_number;
long long credit_helper;
int number_yes;
int number_no;
int number_no_helper;
int number_y = 0;
int number_n = 0;
int number_n_h = 0;
int credit = 0;
int number_f;
long long digit_counter;
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|||||| verfication of the user input section ||||||<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
do // using do/while to get only right values
{
credit_card_number = get_long("enter your Number : ");
}
while (credit_card_number < -1 || credit_card_number == 0);
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|||||| try to know what type of credit card user have ||||||<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// find the last 2 digits of the enterd number
credit_helper = credit_card_number; // |||||| this step because i need (CCN) in another uses down ||||||
digit_counter = credit_card_number;
while (credit_helper > 100)
{
credit_helper = credit_helper / 10;
}
// counting the number digits
while (digit_counter > 1)
{
credit++;
digit_counter = digit_counter / 10;
}
// get the number by digit order
while (credit_card_number > 1)
{
// starts with number_yes >>>>>>>>>>>>>>>>>>>>>>>>>>||Every number must done with his counter||<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
number_yes = credit_card_number % 10;
credit_card_number = credit_card_number / 10;
// numebr_yes loop for number_y counter
while (number_yes > 0)
{
number_y++;
number_yes--;
}
// starts with number_no ||number_no need to * 2||
number_no = credit_card_number % 10;
credit_card_number = credit_card_number / 10;
number_no = number_no * 2;
// statment to check if value have 2 digit inside of it so we can plus them *12 = 1 + 2*
if (number_no >= 10)
{
number_no_helper = number_no;
number_no = number_no % 10;
number_no_helper = number_no_helper / 10;
number_no = number_no + number_no_helper;
// first loop for number_no and the counter for values with more than 1 digit
while (number_no > 0)
{
number_n_h++;
number_no--;
}
}
// second loop for number_no and the counter for values with 1 digit only
while (number_no > 0)
{
number_n++;
number_no--;
}
}
// check if enterd number can be valid (last number should be 0)
number_f = (number_y + number_n + number_n_h) % 10;
//printf("%i\n", number_f);
if (number_f == 0 && credit > 12)
{
// compare the resault of credit_helper from while loop above
// find what credit type based on last 2 numbers
if (credit_helper <= 56 && credit_helper >= 51)
{
printf("MASTERCARD\n");
}
if (credit_helper == 37 || credit_helper == 34 || credit_helper == 36)
{
printf("AMEX\n");
}
if (credit_helper < 50 && credit_helper > 39)
{
printf("VISA\n");
}
}
else if (number_f >= 1 || credit < 13)
{
printf("INVALID\n");
}
}