Question: I need help debugging my program. It is a program using Luhn's algorithm to validate a 16 digit credit card. The program assumes the card

I need help debugging my program. It is a program using Luhn's algorithm to validate a 16 digit credit card. The program assumes the card number is 16 digits long. The output is supposed to either state invalid or valid.However, when I test an invalid credit card number it is still outputting that it is valid instead of invalid. please help!

Here is the code:

#include

#include

#include

int stripper(long long longNumber, int digitNumber) {

long long num = pow(10, digitNumber);

return ((longNumber - ((longNumber / num)*num)) / num) * 10;

}

int isOdd(long int digit)

{

if (digit % 2 == 0)

return 0;

else

return 1;

}

int splitTens(int num) {

return ((num / 10) % 10);

}

int splitOnes(int num) {

return (num % 10);

}

int main() {

long long testNumber, sum = 0;

int i, currDig;

printf("Please enter credit card number ");

scanf_s("%lld", &testNumber);

for (i = 1; i

if (isOdd(i) == 0) {

// even location digit

sum += stripper(testNumber, i);

}

else {

// odd location digit, double the number and add digits of of the number after doubling

currDig = stripper(testNumber, i);

currDig *= 2;

sum += splitOnes(currDig) + splitTens(currDig);

}

}

if (sum % 10 == 0)

printf("Valid Credit Card Number");

else

printf("Invalid Credit Card Number");

getchar();

getchar();

return 0;

}

Here is the output I am getting:

I need help debugging my program. It is a program using Luhn's

Y P D Credit Cardprogram (Running) - Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test Analyze - a - W - 2, Debug - Process: [15540] Creditcardprogram.exe - A Lifecycle Events - Thread: Window Help Continue -|P,II - o | C | - ! : | - A Stack Frame: Quick Launch (Ctrl IQ) P - - Sign in * - - i .io 0 x C 'A , x A ; - oo -| - J x Creditcardprogram.cpE "E CAUsers Jewel\Documents Credit Cardprogram Debug\Credit Cardprogram.exe & Credit Cardprogram Please enter credit card number 7898456733996782 Valid Credit Card Number. + Solution Explorer ER Autos a X Name Autos locals Watch LAI STACK DIBERPIDITY FXOPTION SETTINgs Lommana vinaow Immate Window In 92Col 3 3 Ch I NS Ready O Type here to search Q : a 9 O e 1 Publisha 12:56 PM 3/21/2018 1 A . * a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!