Code Monkey home page Code Monkey logo

credit's Introduction

credit

CS50 Problem Set: https://cs50.harvard.edu/x/2021/psets/1/credit/

This program prompts the user for a credit card number and then reports whether it is a valid American Express, MasterCard, or Visa card number based on the definitions of each's format and structure.

All American Express numbers start with 34 or 37, most MasterCard numbers start with 51, 52, 53, 54, or 55, and all Visa numbers start with 4. Credit card numbers also have a checksum value built into them. A checksum is a mathematical relationship between at least one number and the others. By checking the starting value and the checksum value we can validate which type of credit card the number belongs to or if the number is invalid.

The checksum is calculated using the Luhn's algorithm to determine if the credit card number is valid. The steps for calculation in the program are as follows:

  1. Mutliply every other digit by 2, starting with the number's second-to-last digit, and then add those products' digits together.
  2. Add the sume to the sum of the digits that weren't multiplied by 2.
  3. If the total's last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid.

credit's People

Contributors

lmizner avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.