0
#include <cs50.h>
#include <stdio.h>

int main(void)
{
   printf("Number: ");
   long long cc = get_long_long();
   if (cc >= 4000000000000 && cc < 5000000000000000)
   {
    if (cc >= 340000000000000 && cc < 380000000000000)
    {
        int AO = cc / 100000000000000;
        int A = cc / 10000000000000;
        int AOO = A % 10;
        int AA = cc / 1000000000000;
        int AOOO = AA % 10;
        int AAA = cc / 100000000000;
        int AOOOO = AAA % 10;
        int AAAA = cc / 10000000000;
        int AOOOOO = AAAA % 10;
        int AAAAA = cc / 1000000000;
        int AOOOOOO = AAAAA % 10;
        int AAAAAA = cc / 100000000;
        int AOOOOOOO = AAAAAA % 10;
        int AAAAAAA = cc / 10000000;
        int AOOOOOOOO = AAAAAAA % 10;
        int AAAAAAAA = cc / 1000000;
        int AOOOOOOOOO = AAAAAAAA % 10;
        int AAAAAAAAA = cc / 100000;
        int AOOOOOOOOOO = AAAAAAAAA % 10;
        int AAAAAAAAAA = cc / 10000;
        int AOOOOOOOOOOO = AAAAAAAAAA % 10;
        int AAAAAAAAAAA = cc / 1000;
        int AOOOOOOOOOOOO = AAAAAAAAAAA % 10;
        int AAAAAAAAAAAA = cc / 100;
        int AOOOOOOOOOOOOO = AAAAAAAAAAAA % 10;
        int AAAAAAAAAAAAA = cc / 10;
        int AOOOOOOOOOOOOOO = AAAAAAAAAAAAA % 10;
        int AOOOOOOOOOOOOOOO = cc % 10;

        int AI = AOOOOOOOOOOOOOO * 2 / 10 + AOOOOOOOOOOOOOO * 2 % 10 + AOOOOOOOOOOOO * 2 / 10 + AOOOOOOOOOOOO * 2 % 10 + AOOOOOOOOOO * 2 / 10 + AOOOOOOOOOO % 10 + AOOOOOOOO * 2 / 10 + AOOOOOOOO * 2 % 10 + AOOOOOO * 2 / 10 + AOOOOOO * 2 % 10 + AOOOO * 2 / 10 + AOOOO * 2 % 10 + AOO * 2 / 10 + AOO * 2 % 10;
        int AII = AOOOOOOOOOOOOOOO + AOOOOOOOOOOOOO + AOOOOOOOOOOO + AOOOOOOOOO + AOOOOOOO + AOOOOO + AOOO + AO;
        int FA = AI + AII;

        if (FA % 10 == 0)

        {

            printf("AMEX\n");

        }

        else;

    }

    else if (cc >= 400000000000000 && cc < 500000000000000)

    {


        int VO = cc / 100000000000000;
        int V = cc / 10000000000000;
        int VOO = V % 10;
        int VA = cc / 1000000000000;
        int VOOO = VA % 10;
        int VAA = cc / 100000000000;
        int VOOOO = VAA % 10;
        int VAAA = cc / 10000000000;
        int VOOOOO = VAAA % 10;
        int VAAAA = cc / 1000000000;
        int VOOOOOO = VAAAA % 10;
        int VAAAAA = cc / 100000000;
        int VOOOOOOO = VAAAAA % 10;
        int VAAAAAA = cc / 10000000;
        int VOOOOOOOO = VAAAAAA % 10;
        int VAAAAAAA = cc / 1000000;
        int VOOOOOOOOO = VAAAAAAA % 10;
        int VAAAAAAAA = cc / 100000;
        int VOOOOOOOOOO = VAAAAAAAA % 10;
        int VAAAAAAAAA = cc / 10000;
        int VOOOOOOOOOOO = VAAAAAAAAA % 10;
        int VAAAAAAAAAA = cc / 1000;
        int VOOOOOOOOOOOO = VAAAAAAAAAA % 10;
        int VAAAAAAAAAAA = cc / 100;
        int VOOOOOOOOOOOOO = VAAAAAAAAAAA % 10;
        int VAAAAAAAAAAAA = cc / 10;
        int VOOOOOOOOOOOOOO = VAAAAAAAAAAAA % 10;
        int VOOOOOOOOOOOOOOO = cc % 10;

        int VI = VOOOOOOOOOOOOOO * 2 / 10 + VOOOOOOOOOOOOOO * 2 % 10 + VOOOOOOOOOOOO * 2 / 10 + VOOOOOOOOOOOO * 2 % 10 + VOOOOOOOOOO * 2 / 10 + VOOOOOOOOOO % 10 + VOOOOOOOO * 2 / 10 + VOOOOOOOO * 2 % 10 + VOOOOOO * 2 / 10 + VOOOOOO * 2 % 10 + VOOOO * 2 / 10 + VOOOO * 2 % 10 + VOO * 2 / 10 + VOO * 2 % 10;
        int VII = VOOOOOOOOOOOOOOO + VOOOOOOOOOOOOO + VOOOOOOOOOOO + VOOOOOOOOO + VOOOOOOO + VOOOOO + VOOO + VO;
        int FV = VI + VII;

        if (FV % 10 == 0)

        {

            printf("VISA\n");

        }

    }

    else if (cc >= 4000000000000000 && cc < 5000000000000000)

    {

        int VVO = cc / 1000000000000000;
        int VV = cc / 100000000000000;
        int VVOO = VV % 10;
        int VVA = cc / 10000000000000;
        int VVOOO = VVA % 10;
        int VVAA = cc / 1000000000000;
        int VVOOOO = VVAA % 10;
        int VVAAA = cc / 100000000000;
        int VVOOOOO = VVAAA % 10;
        int VVAAAA = cc / 10000000000;
        int VVOOOOOO = VVAAAA % 10;
        int VVAAAAA = cc / 1000000000;
        int VVOOOOOOO = VVAAAAA % 10;
        int VVAAAAAA = cc / 100000000;
        int VVOOOOOOOO = VVAAAAAA % 10;
        int VVAAAAAAA = cc / 10000000;
        int VVOOOOOOOOO = VVAAAAAAA % 10;
        int VVAAAAAAAA = cc / 1000000;
        int VVOOOOOOOOOO = VVAAAAAAAA % 10;
        int VVAAAAAAAAA = cc / 100000;
        int VVOOOOOOOOOOO = VVAAAAAAAAA % 10;
        int VVAAAAAAAAAA = cc / 10000;
        int VVOOOOOOOOOOOO = VVAAAAAAAAAA % 10;
        int VVAAAAAAAAAAA = cc / 1000;
        int VVOOOOOOOOOOOOO = VVAAAAAAAAAAA % 10;
        int VVAAAAAAAAAAAA = cc / 100;
        int VVOOOOOOOOOOOOOO = VVAAAAAAAAAAAA % 10;
        int VVAAAAAAAAAAAAA = cc / 10;
        int VVOOOOOOOOOOOOOOO = VVAAAAAAAAAAAAA % 10;
        int VVOOOOOOOOOOOOOOOO = cc % 10;

        int VVI = VVOOOOOOOOOOOOOOO * 2 / 10 + VVOOOOOOOOOOOOOOO * 2 % 10 + VVOOOOOOOOOOOOO * 2 / 10 + VVOOOOOOOOOOOOO * 2 % 10 + VVOOOOOOOOOOO * 2 / 10 + VVOOOOOOOOOOO % 10 + VVOOOOOOOOO * 2 / 10 + VVOOOOOOOOO * 2 % 10 + VVOOOOOOO * 2 / 10 + VVOOOOOOO * 2 % 10 + VVOOOOO * 2 / 10 + VVOOOOO * 2 % 10 + VVOOO * 2 / 10 + VVOOO * 2 % 10 + VVO * 2 / 10 + VVO * 2 % 10;
        int VVII = VVOOOOOOOOOOOOOOOO + VVOOOOOOOOOOOOOO + VVOOOOOOOOOOOO + VVOOOOOOOOOO + VVOOOOOOOO + VVOOOOOO + VVOOOO + VVOO;
        int FVV = VVI + VVII;


        if (FVV % 10 == 0)

        {

            printf("VISA\n");

        }

    }

    else if (cc >= 40000000000000 && cc < 50000000000000) 

    {

        int VVVO = cc / 10000000000000;
        int VVV = cc / 1000000000000;
        int VVVOO = VVV % 10;
        int VVVA = cc / 100000000000;
        int VVVOOO = VVVA % 10;
        int VVVAA = cc / 10000000000;
        int VVVOOOO = VVVAA % 10;
        int VVVAAA = cc / 1000000000;
        int VVVOOOOO = VVVAAA % 10;
        int VVVAAAA = cc / 100000000;
        int VVVOOOOOO = VVVAAAA % 10;
        int VVVAAAAA = cc / 10000000;
        int VVVOOOOOOO = VVVAAAAA % 10;
        int VVVAAAAAA = cc / 1000000;
        int VVVOOOOOOOO = VVVAAAAAA % 10;
        int VVVAAAAAAA = cc / 100000;
        int VVVOOOOOOOOO = VVVAAAAAAA % 10;
        int VVVAAAAAAAA = cc / 10000;
        int VVVOOOOOOOOOO = VVVAAAAAAAA % 10;
        int VVVAAAAAAAAA = cc / 1000;
        int VVVOOOOOOOOOOO = VVVAAAAAAAAA % 10;
        int VVVAAAAAAAAAA = cc / 100;
        int VVVOOOOOOOOOOOO = VVVAAAAAAAAAA % 10;
        int VVVAAAAAAAAAAA = cc / 10;
        int VVVOOOOOOOOOOOOO = VVVAAAAAAAAAAA % 10;
        int VVVOOOOOOOOOOOOOOOO = cc % 10;

        int VVVI = VVVOOOOOOOOOOOOO * 2 / 10 + VVVOOOOOOOOOOOOO * 2 % 10 + VVVOOOOOOOOOOO * 2 / 10 + VVVOOOOOOOOOOO % 10 + VVVOOOOOOOOO * 2 / 10 + VVVOOOOOOOOO * 2 % 10 + VVVOOOOOOO * 2 / 10 + VVVOOOOOOO * 2 % 10 + VVVOOOOO * 2 / 10 + VVVOOOOO * 2 % 10 + VVVOOO * 2 / 10 + VVVOOO * 2 % 10 + VVVO * 2 / 10 + VVVO * 2 % 10;
        int VVVII = VVVOOOOOOOOOOOOOOOO + VVVOOOOOOOOOOOO + VVVOOOOOOOOOO + VVVOOOOOOOO + VVVOOOOOO + VVVOOOO + VVVOO;
        int FVVV = VVVI + VVVII;

        if (FVVV % 10 == 0)

        {

        printf("VISA\n");

        }


    }

    else if (cc >= 4000000000000 && cc < 5000000000000)

    {

        int VVVVO = cc / 1000000000000;
        int VVVV = cc / 100000000000;
        int VVVVOO = VVVV % 10;
        int VVVVA = cc / 10000000000;
        int VVVVOOO = VVVVA % 10;
        int VVVVAA = cc / 1000000000;
        int VVVVOOOO = VVVVAA % 10;
        int VVVVAAA = cc / 100000000;
        int VVVVOOOOO = VVVVAAA % 10;
        int VVVVAAAA = cc / 10000000;
        int VVVVOOOOOO = VVVVAAAA % 10;
        int VVVVAAAAA = cc / 1000000;
        int VVVVOOOOOOO = VVVVAAAAA % 10;
        int VVVVAAAAAA = cc / 100000;
        int VVVVOOOOOOOO = VVVVAAAAAA % 10;
        int VVVVAAAAAAA = cc / 10000;
        int VVVVOOOOOOOOO = VVVVAAAAAAA % 10;
        int VVVVAAAAAAAA = cc / 1000;
        int VVVVOOOOOOOOOO = VVVVAAAAAAAA % 10;
        int VVVVAAAAAAAAA = cc / 100;
        int VVVVOOOOOOOOOOO = VVVVAAAAAAAAA % 10;
        int VVVVAAAAAAAAAA = cc / 10;
        int VVVVOOOOOOOOOOOO = VVVVAAAAAAAAAA % 10;
        int VVVVOOOOOOOOOOOOOOO = cc % 10;

        int VVVVI = VVVVOOOOOOOOOOOO * 2 / 10 + VVVVOOOOOOOOOOOO * 2 % 10 + VVVVOOOOOOOOOO * 2 / 10 + VVVVOOOOOOOOOO % 10 + VVVVOOOOOOOO * 2 / 10 + VVVVOOOOOOOO * 2 % 10 + VVVVOOOOOO * 2 / 10 + VVVVOOOOOO * 2 % 10 + VVVVOOOO * 2 / 10 + VVVVOOOO * 2 % 10 + VVVVOO * 2 / 10 + VVVVOO * 2 % 10;
        int VVVVII = VVVVOOOOOOOOOOOOOOO + VVVVOOOOOOOOOOO + VVVVOOOOOOOOO + VVVVOOOOOOO + VVVVOOOOO + VVVVOOO + VVVVO;
        int FVVVV = VVVVI + VVVVII;

        if (FVVVV % 10 == 0)

        {

            printf("VISA\n");

        }

    }

        else;

   }

   else if (cc >= 5100000000000000 && cc < 5600000000000000)

   {
        int MO = cc / 1000000000000000;
        int M = cc / 100000000000000;
        int MOO = M % 10;
        int MA = cc / 10000000000000;
        int MOOO = MA % 10;
        int MAA = cc / 1000000000000;
        int MOOOO = MAA % 10;
        int MAAA = cc / 100000000000;
        int MOOOOO = MAAA % 10;
        int MAAAA = cc / 10000000000;
        int MOOOOOO = MAAAA % 10;
        int MAAAAA = cc / 1000000000;
        int MOOOOOOO = MAAAAA % 10;
        int MAAAAAA = cc / 100000000;
        int MOOOOOOOO = MAAAAAA % 10;
        int MAAAAAAA = cc / 10000000;
        int MOOOOOOOOO = MAAAAAAA % 10;
        int MAAAAAAAA = cc / 1000000;
        int MOOOOOOOOOO = MAAAAAAAA % 10;
        int MAAAAAAAAA = cc / 100000;
        int MOOOOOOOOOOO = MAAAAAAAAA % 10;
        int MAAAAAAAAAA = cc / 10000;
        int MOOOOOOOOOOOO = MAAAAAAAAAA % 10;
        int MAAAAAAAAAAA = cc / 1000;
        int MOOOOOOOOOOOOO = MAAAAAAAAAAA % 10;
        int MAAAAAAAAAAAA = cc / 100;
        int MOOOOOOOOOOOOOO = MAAAAAAAAAAAA % 10;
        int MAAAAAAAAAAAAA = cc / 10;
        int MOOOOOOOOOOOOOOO = MAAAAAAAAAAAAA % 10;
        int MOOOOOOOOOOOOOOOO = cc % 10;

        int MI = MOOOOOOOOOOOOOOO * 2 / 10 + MOOOOOOOOOOOOOOO * 2 % 10 + MOOOOOOOOOOOOO * 2 / 10 + MOOOOOOOOOOOOO * 2 % 10 + MOOOOOOOOOOO * 2 / 10 + MOOOOOOOOOOO % 10 + MOOOOOOOOO * 2 / 10 + MOOOOOOOOO * 2 % 10 + MOOOOOOO * 2 / 10 + MOOOOOOO * 2 % 10 + MOOOOO * 2 / 10 + MOOOOO * 2 % 10 + MOOO * 2 / 10 + MOOO * 2 % 10 + MO * 2 / 10 + MO * 2 % 10;
        int MII = MOOOOOOOOOOOOOOOO + MOOOOOOOOOOOOOO + MOOOOOOOOOOOO + MOOOOOOOOOO + MOOOOOOOO + MOOOOOO + MOOOO + MOO;
        int MV = MI + MII;

        if (MV % 10 == 0)

        {

            printf("MASTERCARD\n");

        }

        else;

   }

   else 

   {

       printf("INVALID\n");

   }
}
10
  • You know what, guys? Forget it. It does not look like anyone can possibly answer that. It's a mess. I've just done nothing but a big mess.
    – Parteemo
    Aug 11 '17 at 13:06
  • However, I still have no idea what to do or how to fix it. I would love some help or suggestions.
    – Parteemo
    Aug 11 '17 at 13:17
  • Wow. It really is a mess. All the credit cards share a common algorithm for checking against simple mistakes, so don't do a separate one for each. Also, use loops instead of infinite number of variables.
    – Blauelf
    Aug 11 '17 at 13:41
  • I first calculated three values: Checksum mod 10, first two digits, and number length. With these three, you can tell all the number types apart.
    – Blauelf
    Aug 11 '17 at 13:42
  • You see, I used separate ones to limit down the first 2 numbers and the number of digits. This is my first time ever coding, and I am just a rising senior, so I have very limited knowledge on how else I can implement this code. I really don't get how I can use a loop for this. My naming of the variables was terrible, however, I can guarantee you that it is correct.
    – Parteemo
    Aug 11 '17 at 17:50
0

I don't want to give away the answer here but I want to send you down a road that gets the 'ol juices flowing.

Look in your tool box for things that you have already. You were on the right path with the modulus call.

Grab a piece of paper and write down 4 numbers (any numbers). how would you about getting the first three numbers using only the basics of mathematics (+,=,*,/)? That's one step.

However, and as an effect of that math, we have a number which is left over from that operation which should be the number we lost!

If we keep doing that, over-and-over, we can figure out what each digit is!

Keep at it!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .