# Need Help

• 10-22-2002
Joes108
Need Help
Hi I need help starting this program
The program check to see if a credit card is valid or not
the number is 16 digits long
EX: Card Number 1234567890123456
Code:

```1. Double the value of alternating digits of the credit card number 1  2  3  4    5  6  7    8  9    0  1  2    3  4    5  6   x2      x2      x2      x2        x2      x2      x2      x2 -------------------------------------------------------------------- 1  4  3  8    5  12  7  16  9  0  1  4    3    8    5  12 2. Add all the digits 1 + 4 + 3 + 8 + 5 + 12 + 7 + 16 + 9 + 0 + 1 + 4 + 3 + 8 + 5 + 12 =98 3. Divide the sum by 10 98/10=9.8```
If the number is evenly divisible then it is valid
If it is not evenly divisible than it is invalud

thanks for the Help Joe
• 10-22-2002
Cshot
Post some code attempts and we'll be glad to help.
• 10-22-2002
Joes108
I want to enter it in as a string then convert it to a integer but how do I do that
• 10-22-2002
Magos
Traverse the string, then add every element in it to the total sum. Note that '0' == 48, '1' == 49, '2' == 50, etc...
Code:

```#define FirstDigit 48 int SumNumbersInString(char* String) {   int Sum = 0;   if(String != NULL)   {       for(int i=0; i<strlen(String); i++)       {         Sum += (String[i] - FirstDigit);       }   }   return Sum; }```
• 10-22-2002
ammar
Do you mean a char * or an ansi string?
• 10-22-2002
Cshot
Never mind

Magos did the char * way in case you're wondering.