Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6633917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:52:08+00:00 2026-05-25T22:52:08+00:00

I am making a credit card validator program in which I am asking for

  • 0

I am making a credit card validator program in which I am asking for a string which is going to be a 16 digit number (credit card #) and I want to convert that into an int array. How do I do that? I need to then multiply every other digit starting from the first digit by 2.

char[] creditNumbers = creditCardNumber.ToCharArray();

creditNumbers[0] = (char)((int)(creditNumbers[0] * 2));
creditNumbers[2] = (char)((int)(creditNumbers[2] * 2));
creditNumbers[4] = (char)((int)(creditNumbers[4] * 2));
creditNumbers[6] = (char)((int)(creditNumbers[6] * 2));
creditNumbers[8] = (char)((int)(creditNumbers[8] * 2));

This is what I made so far but my casting is not done properly. How do I fix the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:52:09+00:00Added an answer on May 25, 2026 at 10:52 pm

    To just get the int array, I would do this:

    creditCardNumber.Select(c => int.Parse(c.ToString())).ToArray()
    

    To check the number using the Luhn algorithm, you could do this:

    bool IsValid(string creditCardNumber)
    {
        var sum = creditCardNumber.Reverse()
                                  .Select(TransformDigit)
                                  .Sum();
    
        return sum % 10 == 0;
    }
    
    int TransformDigit(char digitChar, int position)
    {
        int digit = int.Parse(digitChar.ToString());
        if (position % 2 == 1)
            digit *= 2;
    
        return digit % 10 + digit / 10;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an app that processes sensitive credit card data. If my code
Making a small WCF test program which is based on a Store that has
Making an adobe flex ui in which data that is calculated must use proprietary
I'm making a credit card processing form. The field in question is Name: (first
I'm making a call to PayPal's credit card processor, and after a successful/unsuccessful transaction
I am developing a form that allows users to enter their credit card information
What's the best way to prevent a user from making duplicate credit card transactions?
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
I am creating a page that only contains a gridpanel, I want my gridpanel
While developing a credit card transaction page for a website to transmit data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.