15,844,673 members
0.00/5 (No votes)
See more:
Hi there I'm having some problems with a project for school. I have to use the lung algorithm to create a program to validate a credit card. The if statement at the bottom will not run and print the message at the end. Any help would be greatly appreciated.

C#
```Card_Number = int ( input ( "Please enter your 16 digit credit card number:" ) )
Total = 0
Card_Number_String = str ( Card_Number )
a = int ( Card_Number_String [ 0 ] )
b = int ( Card_Number_String [ 1 ] )
c = int ( Card_Number_String [ 2 ] )
d = int ( Card_Number_String [ 3 ] )
e = int ( Card_Number_String [ 4 ] )
d = int ( Card_Number_String [ 5 ] )
f = int ( Card_Number_String [ 6 ] )
g = int ( Card_Number_String [ 7 ] )
h = int ( Card_Number_String [ 8 ] )
i = int ( Card_Number_String [ 9 ] )
j = int ( Card_Number_String [ 10 ] )
k = int ( Card_Number_String [ 11 ] )
l = int ( Card_Number_String [ 12 ] )
m = int ( Card_Number_String [ 13 ] )
n = int ( Card_Number_String [ 14 ] )
o = int ( Card_Number_String [ 15 ] )

if ( a ) % 2 == 0:
a_Doubled = ( a ) * 2
if ( a ) > 10:
Two_Digit_Number_One = ( a ) * 2
OneDigit1 = str ( Two_Digit_Number [ 0 ] )
OneDigit2 = str ( Two_Digit_Number [ 1 ] )
Two_Digit_Number_One_Sum = str ( ( One_Digit1 ) + ( One_Digit2 ) )
print ( Two_Digit_Number_One_Sum ) ```

What I have tried:

I've tried editing the if statement anyway I can think of.
Posted
Updated 16-Oct-16 18:42pm
Comments
PIEBALDconsult 17-Oct-16 0:58am
Not Lung; Luhn!
https://en.wikipedia.org/wiki/Luhn_algorithm
You're trying too hard. It's really very simple. And you should be able to do it without any ifs.

## Solution 1

The if will work if the 16 digit number starts with an even number
eg:4234567891111110

## Solution 2

This test :
Python
`if ( a ) > 10:`

will never do because a is a single digit.
Did you intend to use `a_Doubled` instead ?

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.

Advice: take a sheet of paper and try to do it by hand, your program should use the same procedure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 200 Richard Deeming 130 Graeme_Grant 60 merano99 40 CPallini 30
 OriginalGriff 1,998 Richard Deeming 835 Dave Kreskowiak 581 Graeme_Grant 539 Patrice T 285

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900