Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago